Topic: Floating numbers

I want to calculate PWM period based on a given RPM.
Frequency = RPM / 60.
Say I have 8 RMP / 60 Sec = 0.13333 Hz.
Period = 1 / Freq.
So the Period = 1 / 0.13333 = 7.5 Sec.
How to represent these calculations in CannyLab ide?


Re: Floating numbers

You can calculate it in milliseconds (ms):

Frequency = RPM / 60000

So the Period in = 60000 / RPM

Thus for RPM = 8 the Period = 60000 / 8 = 7500 ms


Re: Floating numbers

Thank you Konstantin.
Now a conceptual question. I am not fully aware of the device cycles.
Say the canbus sends messages every 10 ms on that address. Based on your calculation the PWM period = 7500 ms.
The first message comes, the device starts to execute the calculations and generate pulses. After 10 ms another message comes, what device will do? It will drop the first execution and go for new one? And on and on? Or the code is blocking and it have to wait 7500 ms to complete the task?


Re: Floating numbers

The diagram actual run time is much shorter than 7.5 sec:
https://cannylogic.com/docs/c7/resource … al_runtime

So you can to implement almost any algorithm you want to control your own software PWM module instead of using system drivers.