The counters (working now thanks to Ariba)
Pliers
Posts: 280
I have been doing a lot of reading and playing with sample codes, but I’m missing something.
I believe the code I need will only be a dozens lines, so I keep reading and trying. I feel close to understanding, but it is getting a little frustrating.
I understand the need to learn on my own, and don’t what to be a “give me” type of person.
That being said, I am putting up my request for some code.
I need to determine the duty cycle of a 5kHz square wave signal and convert it to a 1 kHz signal with the same duty cycle.
I did it with discreet components, and it works.
I know using the propeller would be a smarter way (more reliable, few components).
Also I have been dying to learn machine code.
I’ll keep trying.
Post Edited (Pliers) : 10/14/2008 11:42:37 AM GMT
I believe the code I need will only be a dozens lines, so I keep reading and trying. I feel close to understanding, but it is getting a little frustrating.
I understand the need to learn on my own, and don’t what to be a “give me” type of person.
That being said, I am putting up my request for some code.
I need to determine the duty cycle of a 5kHz square wave signal and convert it to a 1 kHz signal with the same duty cycle.
I did it with discreet components, and it works.
I know using the propeller would be a smarter way (more reliable, few components).
Also I have been dying to learn machine code.
I’ll keep trying.
Post Edited (Pliers) : 10/14/2008 11:42:37 AM GMT
Comments
The duty cycle is constantly changing from 1% to 95% high.
The circuit will be in one pin, out another pin.
I did the samples shown in AN001 Propeller counters.
Post Edited (Pliers) : 10/14/2008 10:10:50 AM GMT
Use the POS-DETECT mode of a counter to measure the high time of the 5 kHz PWM, then you can calculate the DutyCycle.
(if the 5 kHz is constant: High-time / periode time). This can also be made in Spin, then store the value to the Pulswith control variable of the 1 kHz PWM. This PWM can you generate with the code from page 7 of the AN001.
I modified this PWM code from the AN001 with the POSDETECT measuring and get this code:
This code is not tested!!
The recalculation of the Pulswith from 5kHz to 1 kHz is just done with multiplying the high-time by 5.
The Spin code waits for a high->low puls to synchronize, but the exact counting of the pulswith is done by the counter with 12.5ns resolution.
Hope this helps
Andy
I'm looking forward to dissecting it and learning from it.
Very best regards, amigos.
Post Edited (Pliers) : 10/14/2008 10:08:48 AM GMT
What does the thumbs down mean in Ariba's post reply?
Also you don't need to close the thread, but if you want you can just change the title to "The counters (sorted now thanks)" or something similar.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·