[ Log In ]
Potentiometer with adjustable knob.

50K Potentiometer Panel Mount (Non Trimmer) With Knob

$2.45
Qty:
Flex Sensor - Sensing Bending and Displacement

55.37mm (2.18 Inch) Flex Sensor

$8.50
Qty:
3 Foot USB Cable Type A to USB Cable Type A

USB Cable Type A Male to USB Type A Male - 3 FT

$2.65
Qty:
USB 2.0 Cable 10 Foot Type A Male to Type B Male

USB 2.0 Cable Type A Male to Type B Male - 10 FT

$4.80
Qty:
84 oz-in NEMA 17 Stepping motors (also called stepper motor)
Image of the Atmega324p

Atmega324P

$8.50
Qty:

10K timmer potentiometer

10K Trimmer Potentiometer (Through Hole)

$0.85
Qty:
16x2 LCD (Liquid Crystal Display)

16x2 LCD (Liquid Crystal Display)

$12.50
Qty:
White prototyping breadboard with 30 tie strips and two power rails on each side.

White Prototyping Breadboard (2x30 columns of tie strips and 2x2 rows of power strips)

$7.95
Qty:

Programming: Understanding Variance with ADC Conversions

When doing conversions with the ADC (Analog to Digital Conversion), the result may have a variance from conversion to conversion. This gives you a method to calculate this deflection over time and some possible techniques to minimize this deflection, such as using capacitors or using the ADC sleep mode.

To be able to measure the previous result to the current result, the previous result must be stored. Once the current result is captured, another variable is incremented by the absolute value of the difference of the result and the previous result.

First a few global variables are needed to store the previous result, total deflection over time, and the sample count (they start static volatile because the compiler would optimize them out if these keywords were not there):
static volatile uint16_t previousResult = 0;
static volatile int totalDeflectionOverTime = 0;
static volatile uint16_t sampleCount = 0;

The Calculations are happening in the ISR (Interrupt Service Routine):

ISR(ADC_vect)
{
uint8_t theLowADC = ADCL;
uint16_t theTenBitResults = ADCH<<8 | theLowADC;
Send_An_IntegerToMrLCD(13,1,theTenBitResults, 4);

int deflection = theTenBitResults - previousResult;
if (deflection << 0 ) deflection = previousResult - theTenBitResults;
Send_An_IntegerToMrLCD(13,2,deflection, 4);
previousResult = theTenBitResults;
totalDeflectionOverTime += deflection;

sampleCount++;

if (sampleCount >= 300)
{
Send_An_IntegerToMrLCD(8,3,totalDeflectionOverTime, 6);
totalDeflectionOverTime = 0;
sampleCount = 0;
}

ADCSRA |= 1<<ADSC;
}

Comments and Additional Information

Have some code to share? Or additional information? Respond here:

You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.

Description:

Code (optional):