Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC xttiny

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

Bascom Member



Joined: 30 Dec 2019
Posts: 16

blank.gif
PostPosted: Mon Jul 27, 2020 8:44 am    Post subject: ADC xttiny Reply with quote

Greetings to all
I may have missed something, but how do I set the reference voltage for xttina? Of course it works with ASM, but according to the help there should be a config vref configuration. I didn't find a description for her.
The MUX directive is not clear to me in the ADC configuration. I understood correctly that if I don't use it, I can load any channel, but if I use it, only the value of this channel will be returned to the getadc function?

Regards

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

Administrator



Joined: 09 Apr 2004
Posts: 5003
Location: Holland

blank.gif
PostPosted: Mon Jul 27, 2020 9:06 am    Post subject: Reply with quote

you can use CONFIG VREF. For example : config vref=on,adc=1v1,dac=1v1
use CTRL+SPACE to get the values.

I see it is missing from the help. Once i added i will share it here.

for the mux :

Mux position. This bit field selects which single-ended analog input is connected to the ADC. If these bits are changed during a conversion, the change will not take effect until this conversion is complete.
Possible values :
- GND : 0V, GND
- TEMPSENSE : Temperature sensor
- INTREF : Internal reference (from VREF)
- DAC0 : DAC0 output
0-11 : ADC input pin 0-11

this means that the mux selects the input. if you use a number you can select any input. between 0-11 you select the adc inputs. Or you can load &H1F to select GND.
But GND will load the value &H1F , and is more clear.
When you want to change the number dynamic you just assign the ADC0_MUXPOS register with the channel value.

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

Bascom Member



Joined: 30 Dec 2019
Posts: 16

blank.gif
PostPosted: Mon Jul 27, 2020 9:30 am    Post subject: Reply with quote

Thank you
It didn't occur to me to write like that

I forgot to ask. When asking for temperature, does the reference voltage switch automatically or should I watch it?
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5003
Location: Holland

blank.gif
PostPosted: Sat Aug 01, 2020 10:50 am    Post subject: Reply with quote

Quote:
I forgot to ask. When asking for temperature, does the reference voltage switch automatically or should I watch it?


the reference does not switch to the right level. you need to use CONFIG REF like this :
Code:
'configre the internal reference to be 1v1 for both the ADC and the DAC
Config Vref = Dummy , Adc0 = 1v1 , Dac0 = 1v1
 


Here is a sample that uses ADC and measures the internal DAC

Code:

'--------------------------------------------------------------------------------
'name                     : adc.bas
'copyright                : (c) 1995-2020, MCS Electronics
'purpose                  : demonstrates ADC and DAC. Notice that DAC is not available on all processors
'micro                    : xtiny816
'suited for demo          : no
'commercial addon needed  : yes
'--------------------------------------------------------------------------------
$regfile = "atXtiny816.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24

'set the system clock and prescaler
Config Sysclock = 20mhz , Prescale = 1

'configure the USART
Config Com1 = 115200 , Mode = Asynchroneous , Parity = None , Databits = 8 , Stopbits = 1

'configre the internal reference to be 1v1 for both the ADC and the DAC
Config Vref = Dummy , Adc0 = 1v1 , Dac0 = 1v1

'configure the ADC0 to read the DAC
Config Adc0 = Single , Resolution = 10bit , Adc = Enabled , Reference = Internal , Prescaler = 32 , Sample_len = 1 , Sample_cap = Above_1v , Init_delay = 32 , Mux = Dac0

'configure the DAC. We do not output the signal on a port pin otherwise out_enable would be required too
Config Dac0 = Enabled

'dimension a variable
Dim W As Word

Print "Test ADC"

'set the DAC to halve the output which would be halve of 1.1V which is 0.55V
Dac0_data = 127

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

End


please notice that some config statements are changed in the mean time. support was added for multiple devices like dac1, dac2 etc. and the dat files are extended with these devices as well.
i will make an update available later.

to measure temp is explained in the pdf.

in general most devices are only turned on when they are needed. so the reference voltage is off until it is needed. you can override it with a setting.
but you need to set the reference voltage. by default it is 0.55V.

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

Bascom Member



Joined: 30 Dec 2019
Posts: 16

blank.gif
PostPosted: Sun Aug 02, 2020 8:37 am    Post subject: Reply with quote

thank you for answer
I probably wrote it wrong.
Let's take a model example. I need to measure the temperature during the program. I have a reference set to measure voltage at 2.5V. I will recalculate the reference to 1.1V and read the result for MUXPOS 1E hex (here it is interesting because the microchip does not indicate this position in 1604, but in ADC it states that temperature measurement is present). I subtract the offset from the result and multiply by the gain and I should have the chip temperature. Then I return the settings to the state I need for normal system operation. This was my point if it was done automatically (with the config set to MUX = TEMPSENSE) or I have to take care of it myself. Because of the speed, I also have to adjust other parameters of the ADC conversion, which should be given by the catalog sheet for temperature measurement.
Regards RS
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5003
Location: Holland

blank.gif
PostPosted: Sun Aug 02, 2020 10:28 am    Post subject: Reply with quote

all i know is that reading the temp sensor must use 1v1. and the PDF says to set the ref to 1v1. So it will not do that automatic.
But of course you could try it.
The docs are however not really consistent. as i worked my way through all of them i found that it does not always match the atd/inc file form microchip. so some times it is unsure if a device is present or not.
the temp reference is also not consistent between all docs. i did try the internal ref and that worked. the dac also works as do the normal inputs.
the temp sensor result i can not understand. i read 532. the offset is -117 and the gain 148. i get that the result is in Kelvin but when i convert to Celsius i get impossible values.

in the dat file the prodsig_address value is not correct. it must be :
prodsig_address=$1100

Then it will match the value from the normal IO registers.
I will have a look at it later when i have different chips. it is possible the temp. sensor is simply not working.
I would be interested in your values.

_________________
Mark
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