File : main.c Compiler : IAR EWAAVR 2.28a/3.10c Revision :
Support mail : avr@atmel.com
Supported devices : All devices with a ADC can be used. The example is written for ATmega16
AppNote : AVR121 - Enhancing ADC resolution by oversampling
Description : Example of how to use oversampling to increase the resolution. 10-bit result is written to UART after each conversion 16-bit result are written to UART after 4096 10-bit samples
Definition in file main_uart.c.
#include <iom16.h>
#include <inavr.h>
Go to the source code of this file.
Functions | |
__interrupt void | ADCinterrupt (void) |
ADC interrupt routine. | |
void | init_adc (void) |
Enables ADC, Interrupt enabled, ADC-clock=125kHz, VREF=AREF. | |
void | init_counter (void) |
Fast PWM, Clk / 64, Clear OC2 on compare match, 50% duty cycle. | |
void | init_uart (void) |
Initiates the UART, 19.2kbps @ 8MHz cpu-clk., enables transmitter, 8 data, 1 stop, no parity transmitting 8 LSB. | |
void | main (void) |
void | oversampled (void) |
Compensate errors, scaling result, round up, increase averaged result. | |
void | send (unsigned char result) |
Waits for empty transmit buffer, puts data into buffer and send data. | |
void | write_10bit (void) |
Write conversion result to UART. | |
void | write_16bit (void) |
Write 16-bit result to UART. | |
void | write_ascii (double accumulator) |
Convertnumbers to ASCII and sends the result to UART. | |
void | write_space (void) |
Write 'space' before every 16-bit result. | |
Variables | |
double | accumulator = 0 |
Accumulating 10-bit samples. | |
double | result = 0 |
ASCII variable. | |
short | samples = 0 |
Counting 10-bit samples. | |
short | temp = 0 |
Temporary memory location. | |
double | Vin = 0 |
16-bit result |
|
Definition at line 47 of file main_uart.c. References accumulator, and samples. |
|
|
|
|
|
Definition at line 64 of file main_uart.c. Referenced by main(). |
|
Definition at line 179 of file main_uart.c. References init_adc(), init_counter(), init_uart(), oversampled(), samples, and write_10bit(). |
|
|
|
Definition at line 71 of file main_uart.c. Referenced by write_ascii(), and write_space(). |
|
Definition at line 133 of file main_uart.c. References write_ascii(). Referenced by main(). |
|
Definition at line 141 of file main_uart.c. References accumulator, and write_ascii(). Referenced by oversampled(). |
|
Definition at line 86 of file main_uart.c. References result, and send(). Referenced by write_10bit(), and write_16bit(). |
|
Definition at line 149 of file main_uart.c. References send(). Referenced by oversampled(). |
|
Definition at line 27 of file main_uart.c. |
|
Definition at line 28 of file main_uart.c. Referenced by write_ascii(). |
|
Definition at line 31 of file main_uart.c. |
|
Definition at line 30 of file main_uart.c. |
|
Definition at line 29 of file main_uart.c. |