Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

AVRX get adc help

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 314
Location: OR

usa.gif
PostPosted: Tue Jan 18, 2022 12:17 am    Post subject: AVRX get adc help Reply with quote

Hello,
Does anybody have an example of reading the adc of a AVRX128db28?

I've been trying to figure that out but I'm stuck.

Please help,
Dave

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

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jan 18, 2022 9:33 am    Post subject: Reply with quote

Code:

'--------------------------------------------------------------------------------
'name                     : adc-DB.bas
'copyright                : (c) 1995-2021, MCS Electronics
'purpose                  : demonstrates ADC
'micro                    : AVR128DB28
'suited for demo          : no
'commercial addon needed  : yes
'--------------------------------------------------------------------------------
$regfile = "AVRX128db28.dat"
$crystal = 24000000
$hwstack = 64
$swstack = 64
$framesize = 64

'The AVRX series have more oscillator options
Config Osc = Enabled , Frequency = 24mhz
'set the system clock and prescaler
Config Sysclock = Int_osc , Prescale = 1

Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1


'configure the internal reference to be 1v024 for the ADC
Config Vref = Dummy , Adc0 = 1v024

'configure the ADC0 to read the DAC
Config Adc0 = Single , Resolution = 10bit , Adc = Enabled , Prescaler = 32 , Sample_len = 1 , Mux_neg = Gnd , Mux_pos = Ain0

'dimension a variable
Dim W As Word , B As Byte

Print "Test ADC"


Do
  'when getadc() does not have parameters, it will use the current mux setting
  'other options are : getadc(channel)  and getadc(adc0 | adc1 , channel)
   W = Getadc() : Print "W:" ; W
   'output should be 512
   Waitms 1000

Loop

_________________
Mark
Back to top
View user's profile Visit poster's website
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 314
Location: OR

usa.gif
PostPosted: Tue Jan 18, 2022 4:33 pm    Post subject: Reply with quote

Thanks Mark.

Unfortunately the demo hangs at getadc().

What now?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jan 18, 2022 9:03 pm    Post subject: Reply with quote

i will have a look.
_________________
Mark
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Tue Jan 18, 2022 10:00 pm    Post subject: Reply with quote

the adc is different in DB series.

there are some changes required :

_GETADC:
#IF _XTINY<3
Std z+6,r16 ; update mux
#ELSE
Std z+8,r16 ; update mux
#ENDIF

_GETADC_NOMUX:
Ldi r24,1
#IF _XTINY<3
Std z+8,r24 ; start conversion
#ELSE
Std z+10,r24 ; start conversion
#ENDIF

_ADC_NotReady:
#IF _XTINY<3
Ldd r24,Z+8 ; get status
#ELSE
Ldd r24,Z+10 ; get status
#ENDIF

Andi r24,1
Brne _ADC_NotReady ; should be 0 when done



above you can see in bold the changes you need to make to xtiny.lib

or you can cut, copy & paste

as an alternative you can write to support.

this AD converter also has a MUXNEG input. There is no provision is passing this as a parameter. i will add that to 2086.

_________________
Mark
Back to top
View user's profile Visit poster's website
Dave

Bascom Member



Joined: 05 Feb 2005
Posts: 314
Location: OR

usa.gif
PostPosted: Tue Jan 18, 2022 10:44 pm    Post subject: Reply with quote

Thanks you.

That fixed it.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Wed Jan 19, 2022 1:12 pm    Post subject: Reply with quote

ok i was kind of focused to bring out 2085 because of the DB support i was asked about. i rushed out this release Embarassed
i will let you know when i have a new beta for the muxneg parameter.

i dont hope DA and DD also have different a/d

_________________
Mark
Back to top
View user's profile Visit poster's website
oi18ct

Bascom Member



Joined: 08 Mar 2022
Posts: 22
Location: North Branch, Minnesota

usa.gif
PostPosted: Tue Nov 29, 2022 8:25 pm    Post subject: Reply with quote

bingo. works with avr128db32 too.
_________________
Lee
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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