2024-12-29 12:34 PM
Hi everyone,
Happy Holidays!
I need some help if available please.
I need a program that I can install on an STM32 bluepill development board that outputs a PWM signal to emulate a temperature and level sensor as part of a community project.
This is low budget sadly, I have a reasonable level of knowledge in this arena but not enough.
I have the development board and the ability to program it using either USB or an ST-Link. I have a raspberry pi I am using as an oscilloscope. Soldering station, components and so on if.
I have read an awful lot of material relating to the subject of PWM generation using an STM32 bluepill, I’ve not specifically found anything trying to do what I am, close perhaps.
Not close enough with my understanding to alter to suit, so I am looking for help.
The PWM output I need has a frequency of 1hz (1000ms) however it has an initial 10ms pulse followed by a 920ms pause as a checksum which is only sent on initial power on of the 5v switched supply.
Then I need to produce 3 repeating pulses (repeated every 1000ms) One of these pulses has a pulse length that changes over time until a fixed limit.
Ultimately each of the 3 pulses is sent within a fixed 110ms period at the start of the 1000ms interval, with the 3 pulses taking 330ms in total, followed by a 670ms pause then the process repeats with a modification to Pulse A duration every 300,000ms until a fixed period on pulse A of 80ms.
Pulse A (0-110ms) - This is Emulating a Temperature sensor. (minimum pulse duration is 60ms, max pulse duration is 80ms, pause until 110ms)
Pulse B (110-220ms) - This is Emulating a Level sensor (I just need a fixed pulse duration of 88ms from 110ms, so 110ms to 198ms and a pause until 220ms)
Pulse C (220-330ms) - This is Emulating a Diagnosis signal (fixed pulse duration of 44ms from 220ms, so 220ms to 264ms and a pause until 330ms)
Then a pause until 1000ms and repeat.
Written in a different way:
Initial pulse with a length of 10ms
Pause for 920ms
Start timer
At 0ms Pulse A - with a length of 57ms
Then a pause until 110ms.
At 110ms Pulse B with a length of 88ms
Then a pause until 220ms
At 220ms Pulse C with a length of 44ms
Then a pause until 330ms
Then a pause until 1000ms.
Repeat from start timer until 300,000ms
At 300,000ms increase pulse A to 58ms and continue, At 600,000 increase pulse A to 59ms and so on at 300,000ms intervals, until Pulse A is 80ms at which point it gets no longer and stays at 80ms.
On power off, when restarted repeats the above.
A really nice but not important feature would be for the device to be able to lower the length of Pulse A after the main power has been switch off.
For example if i add a rechargeable Li-ion battery and have a switched 5v live that triggers the PWM output, when the 5v switched live turns off a timer reduces pulse A from its last length by 1ms for every 300000 until Pulse A reaches 57ms, then the unit switches off/low power until 5v switched supply returns and the PWM emulation restarts.
If switched supply returns before pulse A reaches 57ms the PWM emulation starts from the length pulse A is at during the countdown.
I would appreciate any help.
2024-12-29 04:54 PM
So not 1 Hz as the STM32 would see it.
You can drive GPIO pin levels at 1 KHz (1ms) resolution via SysTick, perhap 10 KHz if you need sub-ms resolution. Create a schedule lists, and work thru it.
You could clock a pattern to a GPIO via a TIM+DMA to GPIOx->BSRR, this would perhaps afford sub-us placement.
The TIM are all 16-bit, the prescale and period are N-1 values. Prescales from APBx's TIM CLK (see clock tree in RM0008)
You can control pulse separation via period (TIM->ARR) and pulse width per channel via width (TIM->CCRx), you could sequence/chain a pulse train by programming new ARR/CCRx at each update for PWM Mode 1.
You could flip a GPIO pin state for a TIM CHx pin via Toggle Mode, and advancing the TIM->CCRx
There's a cook-book for the TIM, this may give you other ideas.
2024-12-29 05:11 PM
Thank you
More to understand, I need to be able to explain this also. :)