Here's the task. Create program polling ADC at 10 Hz and outputs the measured voltage in volts to the 7-segment indicator block.
- Segment X and Y shows millivolts
- Segment Z shows volts
I recommend use potentiometer/variable resistor
It's important. We are going to use interrupt.
ISR(ADC_vect){
unsigned int value;
TIFR|=(1<<OCF1B); // Output Compare 1 B
value = ADCH; // 8bit 0-255
value = value*0.02; // range 0...5.1 V
adcSEG(value); // from headfile indicator.h
}
This is mathematical equation for init range of voltemeter:
value = value*0.02;
It's example of creation simple digital voltemeter using AVR Microcontroller ATmega16. We are going to make a 5V range digital voltmeter using ADC in ATmega16. Don't forget to use datasheet!
- You can use another MCUs. All you need is datasheet. Don't forget change pins!
- Make project in AVR Studio choosing 8-bit MCU ATmega16.
- Copy code from
adc_voltemeter.c
into yourmain.c
file. - Add headfile
indicator.h
in project. - Build project.
Free