Adjustable Frequency/Duty with counters from Spin?
Is there a trick to get the counters to allow for ANY set frequency(period) with adjustable Duty from 0 - 100 modified from Spin? I've been in the AN001 for several hours and can't find a solution. I'd like to be able to set the counters anywhere from 1Hz to it's max rate, with any duty.
The PWM object appears to use %00100, beyond that I can't tell what is going on in the assembly routine. I am after control of the timeHigh and Period control from Spin, using a counter for PWM instead of giving up a cog.
Post Edited (originator) : 3/13/2007 12:03:41 PM GMT
The PWM object appears to use %00100, beyond that I can't tell what is going on in the assembly routine. I am after control of the timeHigh and Period control from Spin, using a counter for PWM instead of giving up a cog.
Post Edited (originator) : 3/13/2007 12:03:41 PM GMT
Comments
There is still an advantage over doing it in pure assembly/spin I think because the processor has more time to do other things if you want.
Graham
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
If you need a duty cycle of 50%-, you can use *three* counters (two at 50%+, and one to invert that result). Can
anyone figure out how to get a duty cycle of less than 50% (and obviously more than 1/freq) for an arbitrary frequency
using only two counters?
Request for future Prop [noparse]:)[/noparse]
1. Conditional PHSx reset using Pins or counter states(no software) (i.e. Apin & Bpin = PHSx := 0)
2. Conditional PHSx rollback/rollahead(val) Apin & Bpin = PHSx := -1000
Post Edited (originator) : 3/14/2007 2:20:53 AM GMT
If you have 50%+, then a simple inverter at the output will give the 50%-. The inversion could be made via an XOR gate, conditional on another output pin.
For those who are not familiar with the counter pin logic, if you have two counters affect the same pin, the pin will be high if either of the counters set it high, and low only if both counters want low. Therefore by adjusting presetting the relative phase of two counters running at the same frequency, the output can be made high for any % greater than 50%. Freerunning without program intervention.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.