openwch / ch583

The datasheet/SDK/HDK docmentation of Bluetooth LE RISC-V MCU CH582M/CH583M
Apache License 2.0
132 stars 31 forks source link

Temperature sensor documentation incomplete #15

Open karlp opened 2 years ago

karlp commented 2 years ago

The datasheet for the temperature sensor says, in section 15.3.2 Temperature Sensor Sampling The temperature value is obtained according to the conversion relationship between voltage and temperature. Please refer to the evaluation board example program for details.

However, the (only) example ADC program simply reads the temperature sensor channel, without any conversion to a temperature: https://github.com/openwch/ch583/blob/main/EVT/EXAM/ADC/src/Main.c#L51-L62

Please document how we can actually use the temperature sensor.

Hikari-ky commented 2 years ago

You can find the ADC_GetCurrentTS function at the end of the ch58X_adC.c file to convert temperature values: https://github.com/openwch/ch583/blob/main/EVT/EXAM/SRC/StdPeriphDriver/CH58x_adc.c#L214-L232

karlp commented 2 years ago

thank you! missed that!

karlp commented 2 years ago

I've been looking more at this, and I'm afraid I've just got more questions :) I can change the temperature of my ch582m device, and see the temp sensor raw readings go up and down, so I'm confident that it works but getting a real number out of it is... not so obvious. for ~ambient ~24°C, the linked function is giving me -36°C. I've also tried the function at https://github.com/openwch/ch583/blob/main/Application/wristband/firmware/Demo_Firmware/StdPeriphDriver/CH58x_adc.c#L163-L172 which produces different (still "wrong") values. (That function needs a cast to int on C25 otherwise nothing under 25°C is calculated properly anyway)

I've plotted the full range of values these functions generate, and they've giving quite different slopes, but still, it's just two linear equations. What is the value in in ROM_CFG_TMP_25C meant to be giving us? an offset? or a slope? If it's a slope, we need more information, because the two formulas given are both wrong anyway. If it's an offset, we need to be told the constant slope.

here's plotting the values generated by both functions for the ROM_CFG_TMP_25C value on my own board: Screenshot from 2022-05-17 23-06-14

serpent213 commented 1 year ago

@Hikari-ky @zerosensei Would be lovely to get better support from WCH – the chips are really nice, but the (English) documentation and support is still lacking.