Shop OBEX P1 Docs P2 Docs Learn Events
Counter module and pulse counting — Parallax Forums

Counter module and pulse counting

octaloctal Posts: 67
edited 2011-01-12 14:37 in Propeller 1
Hello,
I'm again lost with counters modules !!!
The problem is (seems) simple: I want to generate a 20MHz (18 Mhz exactly) pulses on a pin for a fixed number of times (138 pulses exactly to control an external device).
I used counter module to generate such signal, but if I try to poll the phXs register to stop the signal after having generated exaclty nth pulses, I can't do it precisely. Spin is too slow, asm does not do better at this frequency!!!

I tought to use a second counter (B) to count the number of pulses generated by first counter (A), but how to stop the counter A ???
the only solution I can see is to add an external hardware buffer that disconnect the 20Mhz clock signal from my external device. This can give me more time to stop counter A completely.
Before diving in such brutal solution, I wanted to know if someone here (counter expert) can propose a clever and more elegant solution using only the propeller possibilities?

Regards

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-01-12 09:02
    When two sources drive the same pin, they are ORed at the pin. You could program a second counter with a frequency of 18MHz / 276 so that it, if free-running, it will be high for 138 cycles of the first clock then low for 138 cycles. If it's programmed to use the same pin, that pin will output bursts of 138 18MHz clocks, followed by a steady high for 138 periods, then another burst, etc. It then becomes a matter of timing the second clock to start a usable burst when you want it to and then to shut everything down when it's finished. If the "high" resting state is a problem, you can add an inverter to the pin.

    Another alternative is to use the video generator to produce the burst. It's advantage is that it can produce exactly the pulse stream that you want and gives you enough time between waitvids to do the necessary calculations.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2011-01-12 09:49
    Attached is a demo of a method that does what you ask, to produce a certain number of pulses at a certain frequency, from Spin, up to an including 20MHz. It combines ctra and ctrb on one pin and takes advantage of the internal wired OR logic. Ctra runs at the target frequency, while ctrb runs at the lowest possible frequency but with its phase retarded just enough to produce the required number of pulses. After the burst. there is lots of time (~25 seconds) to stop the counters and retrigger another burst when necessary.

    (v3 works up to almost 40 MHz)
  • octaloctal Posts: 67
    edited 2011-01-12 14:37
    Thank you very much, I'll do tests !!! really amazing these counter modules!!!
    @Phil, I didn"t tought to the video signal generator, I'll check deeply the doc and get back to this post to give my conclusions.

    again, thak you Phil and Tracy ...

    Regards
Sign In or Register to comment.