Posted: Mon Jul 15, 2013 11:59 pm Post subject: ADC will not work with CONFIG PORTx = Output in Bootloader?
Hello Forum,
This problem took a while to figure out.
I have been successfully using a Bootloader that includes display to a LCD for some time. I use PORTC for the data and PORTA for the control lines (Mega 644P in this case).
Bootloader code snippet:
Code:
'============================================= 'Bootloader Mega644p 'Jul 15, 2013 '============================================= $regfile="m644pdef.dat" $crystal=8000000 $hwstack=80' default use 32 for the hardware stack $swstack=64' default use 10 for the SW stack $framesize=64' default use 40 for the frame space ' '======== [ Bootloader Config ] ================= DisableInterrupts'we do not use ints
The troubleshooting began when I used the ADC in the Main Program. The following sample will demonstrate the problem. The ADC will always return 0 (zero).
Code:
'============================================= ' Config ADC test PORTA '============================================= $regfile="m644pdef.dat" $crystal=8000000'internal $baud=9600 $hwstack=128 $swstack=128 $framesize=128
'============================================ 'Scratchpad '============================================ Dim S AsSingle , Ss AsString*8
'============================================ ' Main '============================================ Do
Wadc =Getadc(0)
S = Wadc * Adc10bit_volt
Ss =Str(s)
Print Wadc ;" "; Ss
Wait2
Loop
End'end program
I found out that the CONFIG PORTA=Output in the Bootloader affected the ADC function in the main program. It does not appear to be the case that GOTO _Reset actually resets the port configuration.
Only after I removed the CONFIG PORTA line did the ADC work properly in the Main Program. Is there a good explanation? I thought the CONFIG ADC should set the port correctly?
Thanks for any help.
[PS: Similarly, any CONFIG PORTA.x = Output in the main program will not allow the ADC on that pin to function.][/code]
The goto 0 or the reset address (0) just executes the reset address which will setup the registers. It will not setup the IO registers. These are only set to their default state with a hardware reset.
The xmega can do a soft hardware reset. I did not see this option on normal AVR's but you could use the WD for that. _________________ Mark
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum