Can you get the supply voltage?
Can you get the supply voltage?
How do you get the PyBoard supply voltage so you can watch battery level?
You could take the VIN pin and wire it into a simple voltage divider, with the output going to an ADC pin. This voltage level will drop as the battery is drained, but the 3.3v reference will stay the same, so you can measure the battery level. For more accuracy I think there is an internal voltage reference on one if the ADC ports.
Re: Can you get the supply voltage?
Cool! Is there documentation on this reference voltage via ADC somewhere?
Re: Can you get the supply voltage?
There is VREFINT, mentioned in Chapter 13 of the datasheet:mischko wrote:Cool! Is there documentation on this reference voltage via ADC somewhere?
http://www.st.com/web/en/resource/techn ... 031020.pdf (Page 389)
Re: Can you get the supply voltage?
How do I get at that from Python?
I'm new to microcontrollers and hardware in general, having been a Python/Javascript/Database developer for years.
This is all swimming in the deep end for me.
Thanks,
Scott
I'm new to microcontrollers and hardware in general, having been a Python/Javascript/Database developer for years.
This is all swimming in the deep end for me.
Thanks,
Scott
Re: Can you get the supply voltage?
Unfortunately, if there is an issue with the interrupts or DMA, then I think this will need to be addressed from C.mischko wrote:How do I get at that from Python?
I'm new to microcontrollers and hardware in general, having been a Python/Javascript/Database developer for years.
This is all swimming in the deep end for me.
Thanks,
Scott
Re: Can you get the supply voltage?
Dave,
I'm not clear what you mean by "an issue with the interrupts or DMA".
Do you mean that the VREFINT is only accessible using interrupts or DMA and therefore it needs to be done in C?
I'm not clear what you mean by "an issue with the interrupts or DMA".
Do you mean that the VREFINT is only accessible using interrupts or DMA and therefore it needs to be done in C?
Re: Can you get the supply voltage?
In addition to the 'pyb.ADC' class there is also the 'pyb.ADCAll' class which gives you access to a few additional features of the ADC hardware:mischko wrote:How do I get at that from Python?
I'm new to microcontrollers and hardware in general, having been a Python/Javascript/Database developer for years.
This is all swimming in the deep end for me.
Thanks,
Scott
Code: Select all
>>> dir(pyb.ADCAll)
['read_channel', 'read_core_temp', 'read_core_vbat', 'read_core_vref']
Code: Select all
>>> adc = pyb.ADCAll(12) # Initialize with 12-bit resolution
>>> adc.read_core_vref()
2.410547
Code: Select all
vr = 0
for i in range(1000):
vr += adc.read_core_vref()
pyb.delay(1)
>>> vr / 1000
2.412333
Also, there appears to be a bug in 'adc.c'; according to section 5.3.23 of the hardware data sheet the internal reference voltage is 1.21V +/- 0.03V over the -40C - +105C temp range. (This is standard for a silicon band-gap reference.) There is a stray factor of 2 - I found it in the source, it was incorrectly copied from the code that calculates VBAT. (VBAT can be higher than 3.3V, so the ADC hardware measures it through a 2:1 voltage divider.)
I'll put together the pull request.
-Bryan
(small grammar and code edit)
Last edited by blmorris on Fri Feb 06, 2015 8:05 pm, edited 1 time in total.
Re: Can you get the supply voltage?
Big thanks for the details!
I'm looking forward to getting the new firmware with your fix in it!
I'm looking forward to getting the new firmware with your fix in it!
Re: Can you get the supply voltage?
read_core_vref function is now fixed (wait until 00:30 GMT for new firmware to be available at micropython.org/download).
You will still need to use a voltage divider to bring the VIN voltage down to below 3.3v for input into one of the ADCs. It's simple to do: just 2 large resistors of the same value, say 47kOhm each, in series from VIN to GND, with the connection to the ADC from the middle of the 2 resistors. Then when you measure VIN it will be half of what it actually is.
You will still need to use a voltage divider to bring the VIN voltage down to below 3.3v for input into one of the ADCs. It's simple to do: just 2 large resistors of the same value, say 47kOhm each, in series from VIN to GND, with the connection to the ADC from the middle of the 2 resistors. Then when you measure VIN it will be half of what it actually is.