Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC will not work with CONFIG PORTx = Output in Bootloader?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 468

PostPosted: Mon Jul 15, 2013 11:59 pm    Post subject: ADC will not work with CONFIG PORTx = Output in Bootloader? Reply with quote

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 ] =================
Disable Interrupts                                          'we do not use ints

$loader = $7800
Const Bootloader_start = $7800

' Bootloader     Hex       $LOADERSIZE
'    8000  none  10000
'    7E00        FC00      $400
'    7C00        F800      $800
'    7800        F000      $1000
'    7000        E000      $2000

Const Maxwordbit = 7                                        'Z7 is maximum bit                                   '
Const Maxword =(2 ^ Maxwordbit) * 2                         '128
Const Maxwordshift = Maxwordbit + 1


Config Porta = Output
Config Portd = Output

'===== [ LCD ] =========================
Wport Alias Portc
Dirport Alias Ddrc
Rport Alias Pinc

Rst Alias Porta.4
Lcdcs Alias Porta.5
E Alias Porta.6
Rw Alias Porta.7
A0 Alias Portd.7

Config Rst = Output
Config Lcdcs = Output
Config E = Output
Config Rw = Output
Config A0 = Output


'rest of bootloader


Goto _reset                                                 'Start new program
End
 


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

'==========================================
'Bootloader Config MEGA644P
'==========================================
$loadersize = $1000
Const Bootloader_start = $7800

' Bootloader     Hex       $LOADERSIZE
'    8000  none  10000
'    7E00        FC00      $400
'    7C00        F800      $800
'    7800        F000      $1000
'    7000        E000      $2000

'============================================
'Config ADC
'============================================
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Start Adc

Const Adc10bit_volt = 5.0 / 1023
Dim Wadc As Word

Config Single = Scientific , Digits = 1

'============================================
'Scratchpad
'============================================
Dim S As Single , Ss As String * 8

'============================================
' Main
'============================================
Do

   Wadc = Getadc(0)
   S = Wadc * Adc10bit_volt
   Ss = Str(s)

   Print Wadc ; "  " ; Ss

   Wait 2

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]

(BASCOM-AVR version : 2.0.7.6 )
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4919
Location: Holland

blank.gif
PostPosted: Tue Jul 16, 2013 9:16 am    Post subject: Reply with quote

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
Back to top
View user's profile Visit poster's website
enniom

Bascom Member



Joined: 20 Oct 2009
Posts: 468

PostPosted: Wed Jul 17, 2013 2:24 am    Post subject: Reply with quote

Thanks Mark for your help.

I will modify the Bootloader to time-out by Watchdog at the end of flashing then starting the main program.
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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