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: 165

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: 5921
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: 165

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: 5921
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: 165

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: 5921
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
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Thu Aug 06, 2020 5:19 pm    Post subject: Reply with quote

I'm a lot confused.
When I look at atmelstudio, prodsig_address is 1103 for chips, for example 1604.06 and 816

<memory-segment exec="0" name="EEPROM" pagesize="0x20" rw="RW" size="0x0080" start="0x00001400" type="eeprom"/>
<memory-segment exec="0" name="FUSES" pagesize="0x20" rw="RW" size="0xA" start="0x00001280" type="fuses"/>
<memory-segment exec="0" name="INTERNAL_SRAM" rw="RW" size="0x0200" start="0x3e00" type="ram"/>
<memory-segment exec="0" name="IO" rw="RW" size="0x1100" start="0x00000000" type="io"/>
<memory-segment exec="0" name="LOCKBITS" pagesize="0x20" rw="RW" size="0x1" start="0x0000128A" type="lockbits"/>
<memory-segment exec="0" name="MAPPED_PROGMEM" pagesize="0x40" rw="RW" size="0x2000" start="0x00008000" type="other"/>
<memory-segment exec="0" name="PROD_SIGNATURES" pagesize="0x40" rw="R" size="0x3D" start="0x00001103" type="signatures"/>
<memory-segment exec="0" name="SIGNATURES" pagesize="0x40" rw="R" size="0x3" start="0x00001100" type="signatures"/>
<memory-segment exec="0" name="USER_SIGNATURES" pagesize="0x20" rw="RW" size="0x20" start="0x00001300" type="user_signatures"/>

At 1606 in the catalog sheet they write that it does not have a sensor but it is listed in the AS
<value-group caption="Analog Channel Selection Bits select" name="ADC_MUXPOS">
<value caption="ADC input pin 0" name="AIN0" value="0x00"/>
<value caption="ADC input pin 1" name="AIN1" value="0x01"/>
<value caption="ADC input pin 2" name="AIN2" value="0x02"/>
<value caption="ADC input pin 3" name="AIN3" value="0x03"/>
<value caption="ADC input pin 4" name="AIN4" value="0x04"/>
<value caption="ADC input pin 5" name="AIN5" value="0x05"/>
<value caption="ADC input pin 6" name="AIN6" value="0x06"/>
<value caption="ADC input pin 7" name="AIN7" value="0x07"/>
<value caption="ADC input pin 8" name="AIN8" value="0x08"/>
<value caption="ADC input pin 9" name="AIN9" value="0x09"/>
<value caption="ADC input pin 10" name="AIN10" value="0x0A"/>
<value caption="ADC input pin 11" name="AIN11" value="0x0B"/>
<value caption="Internal Ref" name="INTREF" value="0x1D"/>
<value caption="Temp sensor/DAC1" name="TEMPSENSE" value="0x1E"/>
<value caption="GND" name="GND" value="0x1F"/>

At 1606 in the catalog sheet they write that it does not have a sensor but it is listed in the AS
If I read the values from prodsig_address 1103, the offset is 2 and the gain is 11
If you read the values from prodsig_address 1100, the offset is 255 and the gain is 30
The value from the position 1E converter is 90
In both cases, temperature is nonsense.
Your value already looks more believable at 51 ° C for the case you wrote.
Well, I'll try to explore it through C in my spare time.
Regards RS
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Thu Aug 06, 2020 8:44 pm    Post subject: Reply with quote

It is indeed confusing.
The prodsig_address must be changed to :$1100 in the dat files.
I already did that for the next update. At the moment it is 1103
that is technically ok but the ID fuses are located at 1100.

When you change the dat file the fuses will give the right value.
Of course you can also read the registers directly. They always show the right value.
Some pdf are preliminary. I could not find definitive ones for all processors.
Also because i started long time ago, some chips were moved from one sheet to the other.
There are some errata sheets too.
The inc files are also a mystery as they some times contain info about hardware that is not available. i guess it is not up to date yet. I did inform microchip support.
The last update i downloaded had better files. the xml/atdf and inc files are distilled from production. so i do not get why they are not correct. but maybe it is because they samples/experimented.
Or some things are not correct in the sheets yet.
Anyway, i use both the atdf and the inc files to create the DAT files. Of course i also add some things. And sometimes i remove/remark some stuff when it really does not make sense.
I did not even write code for the temp, i only measured the value. And then i checked in excel to see what Kelvin i got and what it meant in Celsius. I only have tiny816 for test.
I do recall that it worked ok on xmega. I spend some time at it, that is when i found the prodsig_address problem. But even with that i found no solution. Maybe in the future this will be discovered.

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

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Fri Aug 07, 2020 5:57 am    Post subject: Reply with quote

We'll see
By the way, one of the reasons why I used to reach for AVR after 8051 and not PIC were catalog sheets. The microchip has always been confused.
Otherwise, I modified the DAT files, but the results written to me by the programmer seemed strange to me.
I'll try it from their AS and see what kind of data it spills.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Fri Aug 07, 2020 9:21 am    Post subject: Reply with quote

yes the datasheets are very important. atmel did a great job. support was also great.
with microchip the docs are still complete for AVR. Only this new series seem to have some confusing things. but they probably also use copy, paste & edit. and then forget some editing. this happens to me too Embarassed
only support seems bad. it seems there is only 1 person working there. when they are away for a week you dont get a reply. and getting samples is a drama. for some reason i can not order samples from my country. but of course there is farnell which always deliver on time.
Even 20 years ago i asked atmel to have some sort of subscription service where you can get printed data sheets and/or sample chips. and a paid service, i do not mind to pay. but just like atmel, microchip only wants to sell chips. the software and the rest they probably see as a necessary evil.

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

Bascom Member



Joined: 30 Dec 2019
Posts: 165

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

So I tried differently and unfortunately I have to say that it works for them. I'll have to explore Bascom and the features in the data entry file. This is an extract from Arduino's place setting and it works for 1604. It oscillates a bit, but it can be smoothed out.

arduino code in the txt file


Extract from the terminal
Sigrow tempsense1: -1
Sigrow tempsense1 HEX: FFFFFFFF
Sigrow tempsense0: 146
Sigrow tempsense0 HEX: 92
524
525
76650
System temperature is: 25 C

I don't understand tempsense1 and value a bit. Excerpt from the programmer in the picture.
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5921
Location: Holland

blank.gif
PostPosted: Sun Aug 09, 2020 8:03 pm    Post subject: Reply with quote

I see what i did wrong : int8_t sigrow_offset = SIGROW.TEMPSENSE1; // Read signed value from signature row
it is a signed short int. now i get the proper result too. Very Happy
thanks

_________________
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: Mon Aug 10, 2020 1:38 pm    Post subject: Reply with quote

i added a simple option to read the temp in Kelvin
Code:

Const _adc_kelvin = 1
Do
  W = Getadc(&H1e)                                          'get internal temp sensor value
  Print W                                                   'this is in KELVIN
  'to adjust to Celsius, sub 273.15
  Waitms 1000
Loop
 


you define a constant and this will include some code to the getadc().
the result is in Kelvin. but one can easily convert it when required.
it will be in the next xtiny update.

_________________
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