From: Bernard M. <bme...@gm...> - 2008-06-23 01:42:41
|
Hi All, I am having a problem getting the A2D subsytem working on the ATmega128. I have used a modified version of the lcd.frt supplied, but in use I am getting a number that is the same returned for all channels, and applying a voltage to the A2D input has no effect (Port F pins). If I change the scaler parameter for +adc, then I get different numbers, but still not reading the inputs. Is there somethink else that connects the pins to the A2D module, I can't see it in the manual, and the example code doesn't show any extra setup to configure the pins. I also note that in the "waitadc" word, I had to wait for ADSR to go low, not wait for ADIF to go high, as in the example code, otherwise that word would just hang .. also don't know why the original code starts the a2d convertor twice? The code is below, so please have a look and let me know if I am doing anything incorrect .. Many Thanks, Bernard. PS: The other change I made to the original code "butterfly example" was to remove references to the VCP pin. -------------------------------------------------------- Code follows -------------------------------------------------- \ ADC Routines --------------------------------------------------------------------------------------------- marker _adc_ hex \ Register defines 26 constant ADCSRA 25 constant ADCH 24 constant ADCL 27 constant ADMUX ADCSRA 7 portpin: ADEN ADCSRA 6 portpin: ADSC \ Init the ADC sub system : +adc ( scaler channel -- ) ADMUX c! ( -- scaler ) log2 2 max \ lowest 3 bits but at least 2 1 7 lshift or \ msb ADCSRA c! ; \ wait until the adc is finished : waitadc ( -- ) begin ADCSRA c@ [ hex ] 40 and 0= until ; \ fetch the value of the initialized adc channel : adc@ ( -- adc ) ADEN high ( -- ) ADSC high \ start converter waitadc ( -- ) 0 ( -- 0 ) 8 0 do ( -- n ) ADSC high ( -- n ) waitadc ( -- n ) ADCL c@ ADCH c@ 8 lshift + ( -- n adc_i ) + ( -- n ) loop ( -- n ) 3 rshift ( -- adc ) ; |