- Transmit ADC conversion results through software UART
Send '\r'+ 4 hex characters of last ADC conversion every 20 ms
- Test application
Display the ADC result on the command line:
./main.py
You can add a low-pass filtering with the --lpf
option.
Display the ADC result on a graphical dial (requires wxPython):
./main.py --gfx

- config.h
#ifndef CONFIG_H
#define CONFIG_H
#include BOARD_H
#define UART HW_SWUARTA( txd, DIABOLO_PIN_TX, \
rxd, DIABOLO_PIN_RX, \
startirq, (DIABOLO_PIN_RX,port,pcic,irq), \
counter, counter1, \
compare, compare0, \
clkdiv, 1, \
autosync, 51, \
fastreg, (shared,gpior0) )
#endif
- main.c
#include "config.h"
#if HW_ADDRESS((pin,avcc)) == -1
# define VREF vcc
#else
# define VREF (pin,avcc)
#endif
#define COUNTER counter0
volatile uint16_t adc ;
volatile uint8_t x_adc ;
void uart_putbyte ( uint8_t byte )
{
while ( !
hw(stat,UART).txc )
}
HW_ISR( (COUNTER,irq,overflow) )
{
}
{
x_adc = 1 ;
}
int
main ( )
{
hwa( configure, PIN_LED, mode, digital_output );
sleep, enabled,
sleep_mode, idle );
clock, ioclk / 1024,
direction, updown_loop,
bottom, 0,
top, compare0 );
hwa( write, (COUNTER,compare0), 0.02 * HW_SYSHZ / 1024 / 2 );
hwa( enable, (COUNTER,irq,overflow) );
clock, ioclk / 128,
trigger, manual,
vref, VREF,
align, right,
hwa( enable, (adc0,irq) );
hw( enable, interrupts );
while ( !
hw(stat,UART).sync )
for(;;) {
if ( x_adc ) {
uint16_t x ;
do {
x_adc = 0 ;
x = adc ;
} while( x_adc );
uart_putbyte( (x & 0x00FF)>>0 );
uart_putbyte( (x & 0xFF00)>>8 );
}
}
}