Open pelikhan opened 6 years ago
@jamesadevine @finneyj
Yes, I think the way it's configured at the moment should have a range from -4096 to +4095, not 16k?
https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32F0/analogin_device.c#L73 is the line that needs changing, I think.
@mmoskal @VictorDuma
Also - here: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/analogin_api.c#L34
Which is why you're seeing crazy values @pelikhan
@greg-norris we need your fixed sensor value in codal-brainpad to fix the lightsensor/temp sensor.
.getAnalogValue() temperature sensor about 4300. light sensor about 16000
2018-02-08 7:13 GMT-08:00 Peli de Halleux notifications@github.com:
@greg-norris https://github.com/greg-norris we need your fixed sensor value in codal-brainpad to fix the lightsensor/temp sensor.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lancaster-university/codal-mbedos/issues/6#issuecomment-364142147, or mute the thread https://github.com/notifications/unsubscribe-auth/AP7jjTBCiCkgbbf2pOqV9HALOs5cy2jDks5tSw8vgaJpZM4R9ooz .
@jamesadevine what STM is doing is correct - see https://os.mbed.com/docs/v5.7/mbed-os-api-doxy/classmbed_1_1_analog_in.html#a78a2d1c60bd542bacb785b6cc0701013
"16-bit unsigned short representing the current input voltage, normalised to a 16-bit value"
If nrf52 does something else, then it needs fixing and codal should always scale by 6 bits if we want 10 bit result.
@mmoskal mbed appears to be wildly inconsistent... I think the solution here is to apply patches based on target / processor as hinted in my response to @greg-norris 's PR. i.e. subclass MbedPin, and override getAnalogValue and perform the appropriate normalisation.
@finneyj suggests we always normalise to an unsigned 16-bit integer.
Thoughts?
If the NRF52 doesn't return 16 bit value from read_u16
, then it should be fixed, not STM.
@mmoskal Sorry for the confusion. Let me clarify and summarise, as I wasn't clear before.
This issue was filed because @pelikhan was seeing values not normally expected, nor seen on any of our other platforms. My knee jerk reaction was to treat STM as an outlier, when in fact our other platforms using mbed are the outliers; my reaction was incorrect as you have identified. However, this tells us two things: (1) mbed os has inconsistencies in the values returned from read_u16()
(2) based on our previous experiences with values returned from read_u16()
our historic API for the Pin interface is 10-bit.
This means things need to change moving forward:
MbedPin
. (I think yes)MbedPin
and apply the appropriate transformation to meet the API (i.e. an unsigned 16-bit number). We should also add an API to configure the resolution of the ADC if we select this option. MbedPin
and apply the appropriate transformation.I guess it will be some work with the constants in analog sensors etc.
You could probably have a DEVICE_CONFIG constant for the required shift (defaulting to 0) - it would be easier than subclassing.
@pelikhan would we keep 0-1023 in CPX/Maker or go with the 0-65535?
We solve this on our OS by returning a double in the range 0 to 1. If you do not want to use double, scale all values to 16 bits. The problem is this is a needed change in mbed's core.
It seems that the scaling for the analog value at https://github.com/lancaster-university/codal-mbedos/blob/master/source/MbedPin.cpp#L312 does not work for the light sensor on BrainPad. The values returned are in the 16k range.