P2 PASM PWM with NCO
pic18f2550
Posts: 400
in Propeller 2
Hello,
I am looking for an example in PASM about this:
%00111 = NCO duty This mode overrides OUT to control the pin output state. X[15:0] establishes a base period in clock cycles which forms the empirical high-time and low-time units. Upon WXPIN, X[31:16] is written to Z[31:16] to allow phase setting. Y[31:0] will be added into Z[31:0] at each base period. The pin output will reflect Z overflow. IN will be raised whenever Z overflows. During reset (DIR=0), IN is low, the output is low, and Z is set to zero.
So I can understand this better.
Thanks
Comments
This is general form of configuring a smart pin -- this is what the Spin2 function pinstart() does.
You need to use the P_OE flag in the mode setting so that the pin will be driven high and low by the smart pin configuration.
Can I synchronise my programme with it?
You need to clear the flag after every waitse1. You also have not set the mode right.
This version should work:
But I think this is not the mode you want. It's not a usual PWM. The Duty mode has a fixed high time (here) and varies the low time to modify the duty, so the frequency changes with duty. For PWM there are better smartpin modes (triangle and sawtooth pwm).
Andy
Ok, sawtooth PWM could actually be better.
I want to output a variable pulse on a constant time grid. 0...100%.
Do you have a code snippet for me to better understand?
I know you're going to do this in PASM -- but here's how I do it in Spin.
In my simple code I allow the user to specify PWM frequency and the units in 100%. With LED dimming, for example, I specify units of 255 to match DMX lighting control. You could certainly set your units to 100 for 1% resolution. Note that you can change the duty at any time, but it will take effect on the next PWM cycle.
Before popping out to get some lunch I knocked this together and it works! (verified with 'scope)