I noticed in the manual, the ZERO ADC has internal temperature sensor and bandgap channels. Is there a library for reading those? Firmware wiring_analog.c doesn't seem to provide access.
The ZERO / M0 Pro has one configurable ADC with a multiplexer. According to the manual you can indeed access the internal temperature sensor and the bandgap channels. The ADC can be configured to use these by writing to a number of ADC registers and the conversion result and current configuration settings read by reading registers.
A crude example code to modify and read these registers is given as Sketch_2.ino in my post http://forum.arduino.cc/index.php?topic=338640.msg2334526#msg2334526.
The particular register you should need to modify is INPUTCTRL and the bits are MUXPOS[4:0]: Positive Mux Input Selection. See Table 32-14 in section 32.8.8 of the ATMEL manual.
I have not tried this but the above should be enough to get you going.
I wish you success.
Harry J. Whitlow
thanks, I altered your code so that MUXPOS is set to the bandgap channel (25). Ref manual says for temp sensor and bandgap internal channels, the channel value (25) must also be set in the Sampling Time Length, and I did that too. (i think sampling time length just needs to be nonzero)
EDIT: The other piece of magic is setting BGOUTEN and TSEN in the SYSCTRL VREF register.
SYSCTRL->VREF.reg |= SYSCTRL_VREF_BGOUTEN | SYSCTRL_VREF_TSEN;
From your anaRead() I get 2031, so v = (3.3/1.48)*val/4095; gives 1.105v . GOOD for the bandgap.
for temperature (channel 24) need to use 1.0v INTERNAL as reference voltage for ADC,
tempc = 32.2 + (v- 0.772)/.0024; gives me Celsius, though one might wish to calibrate coefficients. v = 1.1*adcval/4095;
Might be nice if the firmware API supported analogReadChannel(channel) or do like Teensy API does and use higher numbered "pins" for the special internal analog channels ...
I know this post is quite old but I'm struggling to get this running and I did'nt find other examples.
Would it be possible to post a complete code example for reading the cpu temperature?