View previous topic :: View next topic |
Author |
Message |
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Tue Jan 18, 2022 12:17 am Post subject: AVRX get adc help |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 9:33 am Post subject: |
|
|
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 |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Tue Jan 18, 2022 4:33 pm Post subject: |
|
|
Thanks Mark.
Unfortunately the demo hangs at getadc().
What now? |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 9:03 pm Post subject: |
|
|
i will have a look. _________________ Mark |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Jan 18, 2022 10:00 pm Post subject: |
|
|
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 |
|
|
Dave
Joined: 05 Feb 2005 Posts: 314 Location: OR
|
Posted: Tue Jan 18, 2022 10:44 pm Post subject: |
|
|
Thanks you.
That fixed it. |
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Wed Jan 19, 2022 1:12 pm Post subject: |
|
|
ok i was kind of focused to bring out 2085 because of the DB support i was asked about. i rushed out this release
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 |
|
|
oi18ct
Joined: 08 Mar 2022 Posts: 22 Location: North Branch, Minnesota
|
Posted: Tue Nov 29, 2022 8:25 pm Post subject: |
|
|
bingo. works with avr128db32 too. _________________ Lee |
|
Back to top |
|
|
|