cancel
Showing results for 
Search instead for 
Did you mean: 

Low Frequency PWM measuring (0 - 4Hz) and trending readings with STM32F030

I am currently using an STM32F030 MCU's external interrupt to measure an incomming PWM signals Frequency, Period, Duty Cycle and Pulse Width. The incoming signal can be between 0 - 4.167Hz. This is working great, capture all three transitions in the PWM signal, time stamp them with HAL_GetTick() and then calculate the wave's parameters using math.

Because as the signal approaches 0Hz it can take a very long time for a full signal to arrive and be characterized. For example, if the wave is 0.02Hz (which is very possible in this application) it will take 50 seconds for the full wave to arrive at the MCU before the MCU can then calculate that and tell the user the frequency. Because of this, it's been requested that I add "trending" to the code where if the last measured frequency is lets say 0.1 Hz and the user changes it to 0.02 Hz then as the MCU is waiting for the next wave to fully arrive it will slowly lower the frequency output to the user and the user can see it move down to 0.02 Hz and stop there rather than having an abrupt change 50 seconds later. Also, I would need to trend in the other direction, so if the user starts at 0.1Hz but then changes that to 0.2Hz the frequency output would slowly rise before settling at 0.2Hz 5 seconds later.

I don't know if it is possible to do this, but if it is can someone tell me how to do so? If I could just assume that it's always going down (which I can't) then I'm more confident it would be possible, but because of the need to trend both up and down I'm questioning if this is even possible.

1 ACCEPTED SOLUTION

Accepted Solutions

I fully agree with what you say: under these circumstances, a trend is indeed not predictable even after one period, because the next period can develop in the other direction.

Good luck anyway!

Regards

/Peter

In order 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.

View solution in original post

3 REPLIES 3
Peter BENSCH
ST Employee

This can be realised, if I understand correctly that you want a sliding display that moves slowly in the respective direction?

You could, for example, not only pick up your measured value when the measurement of the period is completed, but already evaluate the respective intermediate value.

So while the count continues e.g. after 10s = 0.1Hz, then after 11s the display would show 0.091Hz, after 12s 0.083Hz and so on.

Does that answer your question?

Regards

/Peter

In order 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.

You are understanding correctly, and that was more or less my plan before i realized I would also have to increase in frequency as well...i.e. "slide" from 0.1Hz up to 0.2Hz. Since in that situation I'm starting with a 10s period and moving to a 5s period I'm not sure how to "slide up" when after 5 seconds I'll already have the new value and can display it...there is no way to know it should start "sliding up".

Another thing I should mention is this device has no way to know the user has changed the frequency...all this device is doing is monitoring the signal itself, it has no other insight into the rest of the system. I suppose in this situation even in a "sliding down" situation it would have to wait the total period of the currently reported period before it would be able to decide, "Hey, it's been x seconds and I still don't have a new reading...I should start sliding down till I get the next full period." Either way it seems like the user is going to get delayed results based on what they are setting the monitored device to.

I fully agree with what you say: under these circumstances, a trend is indeed not predictable even after one period, because the next period can develop in the other direction.

Good luck anyway!

Regards

/Peter

In order 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.