2022-11-28 04:33 AM
A potentiometer is connected to the breadboard, the middle leg of the potentiometer is connected to the adc pin and the other legs are connected to gnd and 5v.
Led (Led Voltage <1V) - Led will be off
Led (1V<Led Voltage <2V) - Led will blink
Led (2V < Led Voltage < 3.3V) - Led will stay on
I write the codes as in the image, but when it comes to 1V, the codes stop.
2022-11-28 07:39 AM
Hi @H.Portakal,
one of the problems I see in your code is that you convert integer value x to a float value of y without actual need. It's easier for human to read this way, but for the MCU you introduce useless complexity. Remove y and only deal with x.
Also, all three branches contain toggle pin, so they will all blink, at different frequencies. You need to use WritePin to set a specific value.
You can debug the rest.
BR,
J
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2022-11-28 07:59 AM
Try to avoid using float, for exemple use int for coding mV. And enhancing your example in next step would be to use timer pwm output to drive the led so you can dim it like most laptop standby power led dimming up and down....
2022-11-28 08:12 AM
I do it as our teacher shows, I am new to the course, so I did not understand what you said. Any chance to show it through sample code?
2022-11-28 08:13 AM
I do it as our teacher shows, I am new to the course, so I did not understand what you said. Any chance to show it through sample code?
2022-11-28 09:13 AM
Okay, let's say in microvolt
Int Vadc_mV_x1000 = ad x 10000000 x 3 / 4095
If Vadc_mV_x1000 < 1 x 1000000 then...
else
If V... < 2X 1000000 then...
else ....
Something like this as long as the value can be stored within signed 32 bit int quantity.
Understandable ?
In my case, I only use ***_mV
2022-11-28 09:14 AM
One more point, the 3.0V can also be accurately measured by the adc internal channel. Maybe it is 3.28V or 2.97V....
And make sure to calibrate the adc before using it.
2022-11-29 01:33 AM
Hi @H.Portakal,
your teacher is probably coming from PC programing background. Microcontroller programmers try to avoid such computations. To correctly use ADC you need more than ADC_Start and ADC_GetValue. I suggest you look at the ADC_RegularConversion_Polling example from the STM32L0 CubePackage. It's the basic simple functional example on what to do in 5 easy steps.
Just change the input if needed and add the LED control and you are done.
BR,
J
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.