From 17d06b849440eaab17b0b3778e4dae12182eb98c Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Tue, 25 Aug 2009 14:02:47 +0000 Subject: Add VTARGET level detection to the AVRISP project on supported AVR models. --- Projects/AVRISP/AVRISP.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Projects/AVRISP/AVRISP.c') diff --git a/Projects/AVRISP/AVRISP.c b/Projects/AVRISP/AVRISP.c index f14b6545a1..d4ae910f63 100644 --- a/Projects/AVRISP/AVRISP.c +++ b/Projects/AVRISP/AVRISP.c @@ -35,7 +35,6 @@ */ // TODO: Add in software SPI for lower programming speeds below 125KHz -// TODO: Add in VTARGET detection // TODO: Add reversed target connector checks #include "AVRISP.h" @@ -53,7 +52,12 @@ int main(void) for (;;) { - Process_AVRISP_Commands(); + Process_AVRISP_Commands(); + + #if defined(ADC) + /* Update VTARGET parameter with the latest ADC conversion of VTARGET on supported AVR models */ + V2Params_SetParameterValue(PARAM_VTARGET, ((5 * 10 * ADC_GetResult()) / 1024)); + #endif USB_USBTask(); } @@ -73,6 +77,13 @@ void SetupHardware(void) LEDs_Init(); USB_Init(); + #if defined(ADC) + /* Initialize the ADC converter for VTARGET level detection on supported AVR models */ + ADC_Init(ADC_FREE_RUNNING | ADC_PRESCALE_128); + ADC_SetupChannel(VTARGET_ADC_CHANNEL); + ADC_StartReading(VTARGET_ADC_CHANNEL | ADC_RIGHT_ADJUSTED | ADC_REFERENCE_AVCC); + #endif + /* Millisecond timer initialization for timeout checking */ OCR0A = ((F_CPU / 64) / 1000); TCCR0A = (1 << WGM01); -- cgit v1.2.3