Author Topic: atmel  (Read 8075 times)

0 Members and 1 Guest are viewing this topic.

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
atmel
« on: August 10, 2016, 07:17:04 am »
Hello, I would like the temperature via the ADC module with atmel SAMD10. So I created a function for initializing ADC then for the ADC conversion. But now, if I want to get the temperature just me it must change:

Code: [Select]
ADC->INPUTCTRL.reg = (ADC_INPUTCTRL_MUXPOS_TEMP |
ADC_INPUTCTRL_MUXNEG_GND|
ADC_INPUTCTRL_GAIN_1X);

Thanks
« Last Edit: August 12, 2016, 06:36:33 am by hyre »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: atmel
« Reply #1 on: August 10, 2016, 10:40:27 am »
Thats a nice function. Looks good.
================================
https://dannyelectronics.wordpress.com/
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #2 on: August 10, 2016, 04:35:11 pm »
the floats do not work  :-[,  must I check a very specific option?
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: atmel
« Reply #3 on: August 10, 2016, 04:44:25 pm »
Does your compiler issue warnings about converting between formats?
How does your compiler handle the conversion from float to unint_16 and back to float that occurs when you use "calculate_temperature" ?
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #4 on: August 10, 2016, 04:51:00 pm »
The compiler does not emit any mistake linked to the formats yet when the main works, and each time it encounters a float, put it "optimized out" as a value to the variable. It does not cover the floats.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #5 on: August 10, 2016, 04:53:26 pm »
This MCU has no floating point unit, so I'd avoid using floats. At the same time things don't just disappear without warnings, so I'd look at resulting assembly code.

PS: Give topics meaningful titles.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #6 on: August 10, 2016, 04:57:31 pm »
What is even more surprising is that I followed one of documentations in atmel and if I can not use floating, it is me not possible to recover the temperature.
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #7 on: August 10, 2016, 04:59:28 pm »
Sure it is. People have been using fixed point calculations ever since computers existed.

Also, what documentation? And when things don't work, what exactly doe not work?

You really need to give more information if you want meaningful answers.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #8 on: August 10, 2016, 05:09:41 pm »
So I followed this documentation with linear interpolation formulas:
This appnote is for D21, which has more flash and RAM. What is your current Falsh/RAM usage?

What does not work is really the handling of floating.
"Does not work" is not a proper description.

Have you tried a simple program:
Code: [Select]
float a, b;

void main(void)
{
  a = 5.0f;
  b = 6.0f;
  volatile float c = a + b;

  while (1) ;
}
and check what "c" is.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #9 on: August 10, 2016, 05:15:49 pm »
It actually looks like basic floating point operation don't take that much. Using simple + - / * operations resulted in ~2K increase in flash and they do work as expected.

Also, don't look at "optimized" look, since things can really get optimized out. Assign your value to a volatile variable, which can't be optimized and check that variable.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #10 on: August 10, 2016, 05:20:25 pm »
For a simple example like this it works.

As regards the use of Flash and Ram at the moment, I only this code so it astonish me to know that the memory becomes full puique when I compile this appears:
Program Memory Usage: 9552 bytes 58.3% Full
Data Memory Usage: 1096 bytes 26.8% Full


But just to get the temperature, I find that the memory is still very overloaded. But how do I will be possible to get the temperature without solicit as much memory?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #11 on: August 10, 2016, 05:25:12 pm »
Yes, you need to understand exactly what is going on in your system. For instance, what type of temperature sensor you are using? Most analog temperature sensors are non-linear devices, so you will need to have a lookup table. They are also not that accurate, so integer degrees values will be sufficient in most cases.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #12 on: August 10, 2016, 06:00:27 pm »
To get stated accuracy out of the internal  sensor you do need to read calibration values and apply corresponding transformations. "34.9.8 Temperature Sensor Characteristics" describes all the formulas. You don't need to use floating point, it all can be done with integer calculations.

But to get basic uncalibrated reading, all you need is data in the table Table 34-28:

Temperature sensor output voltage @ 25 C = 0.688 V
Temperature sensor slope = 2.16 mV / C

I'm assuming you are using 12-bit ADC and 1 V as reference. We will use microvolts for voltages, so we can stick to integer numbers and maintain accuracy of calculations.

ADC reading at 25 C will be 4096 * 0.688 = 2818.
ADC input voltage is Vin[uV] = ADC * 1000000 / 4096 = ADC * 244

And the code to get temperature reading is
Code: [Select]
int32_t temp = 25 + (((int32_t)ADC - 2818) * 244) / 216;

Also, internal temperature sensor is even less accurate than external ones. It has +/- 10 degree accuracy over all operating conditions.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #13 on: August 10, 2016, 06:25:08 pm »

If I understand correctly, I have to change the way of coding linear interpolation so as to not have floating.

In case I use the uncalibrated basic reading, I must therefore use the following formula:

  int32_t temp = 25 + (((int32_t) ADC - 2818) * 244) / 216;

But I have a question about this case. I must then change the ADC_result on the configuration of the conversion?

But the main is
Code: [Select]
int main(void)
{
        SystemInit();
ADC_Init();
uint32_t temp = ADC_Result();
uint32_t temp2 = 25+((temp-2818)*244)/216;
    while (1)
    {
    }
}

 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #14 on: August 10, 2016, 06:30:01 pm »
But I have a question about this case. I must then change the ADC_result on the configuration of the conversion?
What do you mean?

Your code roughly looks OK, make sure that some of those functions actually start a conversion. And use int32_t instead uint32_t, otherwise you will get incorrect results for negative temperatures.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #15 on: August 10, 2016, 06:43:59 pm »
OK but the problem is that completely out of me as temperature halucinante temp2 1023 or 1426 ..
This varies enormously .. In the room it has to 22 degrees
When the converter reached 4095 Temp2 variable will be  from 1467 up

I don't understand the  result
« Last Edit: August 12, 2016, 06:38:52 am by hyre »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #16 on: August 10, 2016, 07:51:25 pm »
So what are your ADC settings? And that is the raw reading? You should start with that, not some complicated formulas.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #17 on: August 10, 2016, 07:57:16 pm »
What are those raw results (exact numbers)? Are they stable?
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #18 on: August 10, 2016, 08:02:51 pm »
temp=4095              ;  2460          ; 4095
temp2=-6838658    ; -4889368    ; -7166954
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #19 on: August 10, 2016, 08:07:32 pm »
4095 is a good sign of overflow. Do you have temperature sensor enabled (TSEN in VREF register)?

Also, if you plug in 4095 into the formula, you will get 1467, not that crazy negative number, so there is also something wrong with the way you interpret results of the calculation.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #20 on: August 10, 2016, 08:25:47 pm »
I made some adjustments in my functions it seems more stable in adc_result function () I get the results:

a = 330 result = 3088
a = 320 result = 3080
a = 324 and result = 3083
But these values are high and do not reflect the room temperature
« Last Edit: August 12, 2016, 06:39:37 am by hyre »
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #21 on: August 10, 2016, 08:56:21 pm »
I get similar readings on my board.

Well, it is possible that without calibration direct temperature readings are totally useless. So you need to do similar integer math for those calibration formulas.

Just keep your voltage readings in microvolts and you won't need floating point math.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #22 on: August 10, 2016, 09:05:09 pm »
I agree with you, but if I want to use this calibration function that atmel do you recommend to tempR et INT1Vr?
What do you mean? Last part of this sentence makes no sense.

I'd recommend go over the section of the datasheet that describes the math, and implement it from scratch.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #23 on: August 10, 2016, 09:07:27 pm »
Note that even if you apply calibration procedure, your readings still will be accurate to +/- 10 degrees C. I'm not sure why this would be useful in any way.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #24 on: August 11, 2016, 04:40:07 pm »
I can try this code, but can you please find where NVMCTRL_TEMP_LOG, FUSES_XXX_Msk and FUSES_XXX_Pos, and post the values here. They are not a part of standard headers, so they are probably defined somewhere in ASF, and I'm to lazy to start digging for that stuff.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #25 on: August 11, 2016, 04:47:06 pm »
I think it would be simpler to include <asf.h> at the top of the code right?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #26 on: August 11, 2016, 04:49:25 pm »
I don't have ASF, I have simple bare-metal projects (https://github.com/ataradov/mcu-starter-projects/tree/master/samd10). And ASF is not really freely searchable, so I can't use it unless I create a project in AS, which I don't have either.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #27 on: August 11, 2016, 05:01:57 pm »
Now I'm missing NVMCTRL_TEMP_LOG.

BTW, what file did this come from? I may need to update my header files.
« Last Edit: August 11, 2016, 05:04:17 pm by ataradov »
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #28 on: August 11, 2016, 05:06:26 pm »
This Software Temperature Log row can be read at address 0x00806030.
it comes from nvmctrl.h file
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #29 on: August 11, 2016, 05:22:58 pm »
Ok, I have those definitions for all devices, but D10. And when I define them, manually, I get clearly invalid (all 0xff) calibration data on my device. So it is possible that this is device revision dependent.

Let me figure out what is going on here.
Alex
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #30 on: August 11, 2016, 05:49:47 pm »
My header files were way old. After updating, I have all those defines.

It also looks like my device does not have any calibration data. I assume you use SAM D10 Xplained Pro? Can you try attached project and see what it prints on the COM port?

In my case I get:
Code: [Select]
Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
4053  2147483647
4056  2147483647
4055  2147483647
4056  2147483647
4057  2147483647
4057  2147483647
4058  2147483647
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #31 on: August 11, 2016, 06:23:05 pm »

which update did you do and what is the manipulation you have achieved?
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #32 on: August 11, 2016, 06:25:27 pm »
Update of header files in my project to the most recent ones from AS.  This does not affect you, since you created your project recently. I had my projects created when this device first came out.

What do you mean by "manipulation"?
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #33 on: August 11, 2016, 06:36:43 pm »
At the terminal I have not the "hello world" only appears I only 3 digits
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #34 on: August 11, 2016, 06:39:06 pm »
Please be more specific. I'm not going to pull information from you, it is a waste of my time.

Can you copy exactly what you see?

Keep terminal program open and restart the project.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #35 on: August 11, 2016, 06:43:50 pm »
I changed of terminal
Quote

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
224  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
225  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
222  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
225  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
225  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
224  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
226  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
224  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
224  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
225  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
222  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

Hello, world!
0xffffffff 0xffffffff 255 15 255 15 -1 -1
223  2147483647

 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #36 on: August 11, 2016, 06:46:30 pm »
Ok, so your board also returns 0xffffffff. Can you check what those values are on your project? It is possible that they are not accessible until something is enabled.

Also, values 223-225 are way too low for some reason, but it is not important right now.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #37 on: August 11, 2016, 06:53:20 pm »
This address 0x00806030 contains no calibration data so this is a big problem
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #38 on: August 11, 2016, 06:55:16 pm »
So you have confirmed that even your demo application does not contain anything there? Don't trust my program, it is possible that you have to enable some clock that is not enabled, although I don't see anything obvious.
Alex
 

Offline hyreTopic starter

  • Contributor
  • Posts: 16
  • Country: cl
Re: atmel
« Reply #39 on: August 11, 2016, 06:58:14 pm »
the memory is :
 

Offline ataradov

  • Super Contributor
  • ***
  • Posts: 11258
  • Country: us
    • Personal site
Re: atmel
« Reply #40 on: August 11, 2016, 07:57:19 pm »
Yeah, looks like there is no calibration data in those devices. They may be engineering samples or something.

For the actual temperature reading, you will get better results if you use lookup table anyway. Just collect what ADC readings correspond to what temperatures and use that table to lookup the temperature based on the ADC reading. This table will be non-linear, so you will get better results than any linear approximation.

There may be some variability between the devices, so you will need to check that as well.
Alex
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf