0

I am working wiht a partner on a project and we are trying to make sure we can read a temperature sensor as an input to find the average value of the temperature over the span of around 10 seconds. We just are unsure of how to store the value of the temperature sensor in a register. Any help is greatly appreciated.

We have tried to find answere online but have only encountered one type of temperature sensor and it seemed to be a daunting task saying we needed to create a "bare metal environment" WE have the functions of the code essentially written we just need to get the input in order to use said functions.

  • You just need to know how wide the value is, then can store in a register that wide. To average 10 values, you just need a running sum that is sufficiently wide, then divide by 10 when you're done with 10 samples. (If the values are close to the limit of the temperature width, then might need to keep a wider sum value to prevent overflow. Also if collect 8 samples, only divide by 8, which is easier on processors that don't have divide instruction.) – Erik Eidt Apr 18 '23 at 03:47
  • bare metal does not mean assembly language. but saying that assembly language is just another programming language so you would do this the same as you would in any other. if assembly is a struggle then learn the peripheral in some other language first to cover that knowledge then switch to whatever your final programming language is. – old_timer Jul 11 '23 at 00:39
  • 99% of bare metal is reading and hacking at it with throwaway code. much less than one percent of your time (and about the same percentage of code written) is the actual final program. The rest is the knowledge you use to get there. – old_timer Jul 11 '23 at 00:41
  • there are more, different, temperature sensors than you have time to learn. this one is a voltage based so you have to do the electrical engineering to fit it into your design, and then use an adc in your I assume mcu. (you have something arm7 based??? fun) – old_timer Jul 11 '23 at 00:43
  • others you just need to connect with spi or i2c which you can do with a peripheral in your mcu or you can bit bang with gpio. the analog is all in the part again, read, research, experiment. how do you eat an elephant, one bite at a time. divide into individual steps, boot the mcu into an infinite loop, turn on an led, blink an led, get the uart working so you can "see", get the adc working if that is the path you want, big bang some spi (spi is easier than i2c), etc, etc. – old_timer Jul 11 '23 at 00:49
  • "bare metal environment" includes vendor supplied libraries, arduino, mbed, etc. and those environments have complete support for some number of sensors including temperature. a few minutes to a few mouse clicks, wire as shown on diagram and you have temperature readings. – old_timer Jul 11 '23 at 00:52

0 Answers0