Shop OBEX P1 Docs P2 Docs Learn Events
To CTRA or not to CTRA that is the question — Parallax Forums

To CTRA or not to CTRA that is the question

RS_JimRS_Jim Posts: 1,768
edited 2009-09-08 05:45 in Propeller 1
Ok, so I am beating my head against the wall in trying to understand counters.· According to Page 14 of the AN001 propeller Counters v1.0 "The PHSA register would contain the number of milliseconds BPin has been high and in theory with and 80 MHz system clock would be able to measure the duration of an event on BPIN from 1 ms to nearly 50 days with a millisecond reolution." So I developed a simple test program with 2 counters outputing on pins 1 and 2 a 1 millisecond pulse and a 1 second pulse.

Here are the results:
Timer Results:··············· -1557754540
Timer CTRA BIN:·············· 0110000000000000000000100000010
Timer PinMask :·············· 0000000000000000000000000000110
Timer CTRA Hex :············· 30000102


The two counters do put out 1ms and 1 sec pulses, according to my usb oscope( which doesnot like reading both signals at the same time)

I am running this on a Prop Demo board.· Any ideas

Comments

  • kuronekokuroneko Posts: 3,623
    edited 2009-09-06 02:04
    Radio Shack Jim said...
    Timer CTRA Hex : 30000102
    That value doesn't make sense. According to your source you want Logic A & B.
    • $60000401: A&B, B=2, A=1, %11000<<26|2<<9|1
    • $60000202: A&B, B=1, A=2, %11000<<26|1<<9|2
    It usually helps if you write the counter mode in the form of mode<<26|Bpin<<9|Apin. It's easy to miss a bit otherwise.

    Also, after re-reading the application note, you want the gate pulse from a counter in DUTY cycle mode not NCO.
    The application note said...
    Such a system could be achieved by using two counters, the first in Duty Cycle mode configured to output a high once a millisecond ...
    Post Edited (kuroneko) : 9/6/2009 2:20:03 AM GMT
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-09-06 04:50
    Does that mean that the duty cycle mode must have a duration of only 1 clock cycle to count 1 per msec?
    RS_JIM
  • kuronekokuroneko Posts: 3,623
    edited 2009-09-06 05:07
    Radio Shack Jim said...
    Does that mean that the duty cycle mode must have a duration of only 1 clock cycle to count 1 per msec?
    Correct, one clock cycle every 1ms. As long as a logic counter is enabled, each clock pulse (e.g. at 80MHz) will add frqx into phsx.
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-09-06 06:18
    Ok, so the fun part is figuring out how to configure that!
  • kuronekokuroneko Posts: 3,623
    edited 2009-09-06 06:25
    Radio Shack Jim said...
    Ok, so the fun part is figuring out how to configure that!
    Isn't it always? [noparse]:)[/noparse] Anyway, what are you trying to do in the end?
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-09-06 11:44
    I have 2 different events that I want to time with ms resolution. I thought that the counters were the perfect way to do it. However I think that It will be easier to use a cog to generate a running MS timer and outputing it to common memory where my other cogs can reference it when it is needed. Jonny Mac has an interval timer that has MS accuracy and that might work. I just thought that the counter was the perfect way to do it since the notes mentioned it as an "ideal" method for tracking long term events.

    rs_jim
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-09-07 02:07
    So does anyone have the numbers to develop a dutycycle timer with a rate of 1KHz with a 1 2 4 or 8 cycle duty?
    rs_jim
  • hinvhinv Posts: 1,255
    edited 2009-09-07 19:21
    Hi rs_jim,

    If you do it in the cog, you can just use the waitPNE command to stall the cog and then when your even comes in, it will continue your program. You would then grab cnt (that count's the 80MHz clock), do the math, and you got it. Of course, you will have to account for the wrap of CNT at roughly every 53 seconds at 80MHz.
    For doing it in a counter, I would recommend looking over the counters PE Lab at www.parallax.com/Portals/0/Downloads/docs/prod/prop/PELabsFunBook-v1.1.pdf

    Doug
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-09-08 00:53
    Doug,
    The PE labsfunbook only addresses duty as part of a changing pwm project. In the counters apnote there is a brief mention of using a 1 millisecond pulse to time an external event from 1 ms to 53 days. However I dont have any idea how to generate 1 clock wide 1 ms pulse which is what would be required to make this happen. When I use a 1 ms square wave, I get all of the clock counts that occur during the on cycle of the wquare wave. Looking at the logic diagram, when both signals are hi(using logic A and B) phsa is counting the clock pulses. I only want to count events. It appears the only to achieve that is to have a 1 clock wide event so that it only counts 1! A 1 millisec timer of a single clock cycle or even 4 clock cycles that ran unattended without tying up a cog would be really nice!
    rs_jim
  • kuronekokuroneko Posts: 3,623
    edited 2009-09-08 01:13
    Radio Shack Jim said...
    A 1 millisec timer of a single clock cycle or even 4 clock cycles that ran unattended without tying up a cog would be really nice!
    I don't really see the problem. Program the counter for duty cycle (mode %00110), set frqx to freq*4G/clock, e.g. 1K*2^32/80M=53687 and you get a 999.998Hz single pulse signal. A duty cycle counter only generates a high output when there is an overflow from adding frqx to phsx, i.e. the overflow is the output, not phsx[noparse][[/noparse]31].

    Post Edited (kuroneko) : 9/8/2009 1:26:59 AM GMT
  • hinvhinv Posts: 1,255
    edited 2009-09-08 03:53
    So I understand the problem clearer. Are you saying that you want a 12.5ns high pulse every 1ms?

    Can you explain how this applies to the real world ie, what do you want to accomplish?
    I think i don't have a good understanding of the problem.


    Thanks,
    Doug
  • RS_JimRS_Jim Posts: 1,768
    edited 2009-09-08 05:37
    Doug,
    I was trying to develop an interval timer with 1 ms resolution to time an external event. That time can vary any where from 0.5 seconds to 1.5 seconds. Having millisec accuracy if fine for the application. I don't know if a 1 clock cycle wide pulse can be recognized by the prop however as I tried an experimental routine:
    mov time,cnt
    add time,MS_01
    or dira,#1
    :lp xor outa,#1
    xor outa,@1 That should give a 4 clock cycle wide pulse
    waitcnt time,MS_01
    jmp #:lp
    I am not sure that this will work as I have not tried it against my 1 second timer to see if I get 1000 pulses stored in the counter.



    kuroneko

    So using the same number that generates a 1 MS squarewave in nco mode will generate a 999.98 Hz signal with a single pulse out every cycle?

    rs_jim
  • kuronekokuroneko Posts: 3,623
    edited 2009-09-08 05:45
    Radio Shack Jim said...
    So using the same number that generates a 1 MS squarewave in nco mode will generate a 999.98 Hz signal with a single pulse out every cycle?
    Yes, provided you use duty cycle counter mode.
Sign In or Register to comment.