Picomite Phase Correct PWM


Author Message
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2542
Posted: 11:38am 27 Aug 2022      

  Volhout said  [...]
Maybe it is better to add a 4'th parameter to the PWM command, that when not used keeps the standard mode.

i.e. PWM frequency, duty cycle A, duty cycle B, "P"

I have seen that many PWM's have this "phase correct" feature, so it could even become a standard extension of MMBasic.

Volhout


the downside with an extra parameter is that it requires additional complexity in the interpreter to decode it: distinguishing between a letter ("P") and a number, generating an error if it is the wrong letter, etc. in the case of the MX170 at least, there is almost no spare flash available for this sort of thing.

a negative frequency, on the other hand, can be checked with just a couple of machine code instructions. then a couple or three more instructions to divide the frequency by -2, and a single poke to change the PWM configuration register. potentially it may only involve growing the firmware by a handful of bytes - a far smaller barrier when flash space is scarce.

it also means the new feature can be 'silently slipped in' without needing to document it  


cheers,
rob   :-)