Shop OBEX P1 Docs P2 Docs Learn Events
ctrx neg/pos edge detect mode question.. — Parallax Forums

ctrx neg/pos edge detect mode question..

RinksCustomsRinksCustoms Posts: 531
edited 2008-04-09 20:14 in Propeller 1
If a counter were setup in neg-edge mode to count a pulse, & frq = 1, would it count clocks from the first neg-edge to the next neg-edge?

Also, is there a definition of a neg-edge? Is it just below 3.3V? Is it at 1/2 VDD?, Is it somewhere between 1.65V & 3.3V?

Thanks in advance..

pri get_freq(maf_pin) : frequency | pulse
{measure next available pulse on MAF_pin, then convert to a frequency number}
  ctra[noparse][[/noparse]30..26] := %01110
  ctra[noparse][[/noparse]5..0] := maf_pin
  frqa := 1
  phsa~
  dira[noparse][[/noparse]maf_pin]~
  waitcnt(50_000 + cnt)
  pulse := phsa #> 0
  frequency := (f.fround(f.fmul((f.div(1,clkfreq)), pulse)))
  
return frequency

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
E3 = Thought

http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-08 00:38
    A negative edge is defined as a clock cycle with the input high followed by a clock cycle with the input low. The count occurs on the 2nd clock cycle. Logic high is anything above 1/2 Vdd while logic low is anything below 1/2 Vdd (roughly). There's another mode which counts whenever there's a logic low present (on each clock cycle).
  • RinksCustomsRinksCustoms Posts: 531
    edited 2008-04-08 01:57
    Yeah, that's what I was thinking, but wasn't sure. And will the neg-edge mode count from neg-edge to neg-edge? The sensor outputs a variable frequency, but it's not a symetrical waveform, it's more like a positive voltage with negative spikes for the frequency. The frequency range is from 750-12,000Hz so the prop should have no probem measuring pulses.

    Maybe pos detect mode would work better?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-04-08 15:43
    Neg edge counts the number of edges, not the duration between edges.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • RinksCustomsRinksCustoms Posts: 531
    edited 2008-04-09 01:03
    ah, was studying the counter mode table in the manual today and kinda figured that. I suppose i'd have to implement some kind of single pass counter loop with ctrb where ctra detects the first neg-edge that sets frqb to 1 then stops counting with frqb = 0 when the second neg-edge is detected:

    ...
     
    repeat while phsa == 1
      frqb := 1
    frqb := 0
     
    ....
    

    or something like this then. Thanks guys for pointing the way. I do enjoy a good puzzle with the occasional road signssmile.gif
    Best Regards,
    Mike R. ( how many mikes does that make it now? )

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.

    Post Edited (RinksCustoms) : 4/9/2008 5:00:23 AM GMT
  • CJCJ Posts: 470
    edited 2008-04-09 01:20
    why not just use pos detector mode and have the cog:
    wait for a low,
    snapshot the value counted and reset the count,
    wait for the return to high
    then wait for the next low?

    this will give you the high time/time between pulses

    did this both ways at the same time on a 250kpps peak signal in the n64 and gamecube controller drivers I wrote. only used one cog too, man I love this chip.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.

    Post Edited (CJ) : 4/9/2008 1:25:54 AM GMT
  • RinksCustomsRinksCustoms Posts: 531
    edited 2008-04-09 04:56
    @CJ - if i just counted the low, it wouldn't work because it's not a symetrical wave, not sure i folow what your trying to lay down...·It's a little complex in that it's almost a 12V constant signal with negative spikes coresponding to frequency. So i figure the easiest way to read the MAF is to use CTRA in neg-edge mode to act as a trigger for CTRB to start counting clocks (12.5nS @80MHz)

    idea.gif·~Brain wave~~idea.gif

    And instead of counting each of ten pulses and converting each one to a freq and passing it back as an avg·freq number, I can just wait until PHSA == 9 (since edge-detect mode will count edges instead of accumulating FRQx to PHSx) and stop the counting on CTRB and just divide all the accumulated clock ticks in PHSB by 10 and convert that into an averaged frequency to be passed back to the calling method!

    I don't have the spin file on my tower, but i can give a quick summary of what i'm trying to do with these two counters:

    Monitor output pulses from a Mass Airflow Sensor
    measure ten pulses or so·then average them, use 1/x to convert to a freq
    convert the average frequency into a grams/sec measurement using a data "table" lookdown/up search method·- ( two tables, 102 entries each)
    and a linear interpolation formula to output the final grams/sec value

    I know SPIN is probably not fast enough to do all this in under 100mS, but I dont know any PASM - or any other kind of ASM. And none of this object has been actually tested yet, but it does compile so far, so i am hopeful there wont be too many bugs to iron out, I should be ready for actual testing this weekend (when I put my trans back in my firebird).

    I do love these forums so! A great place for inspiration, and of course REALLY good answers - no sarcasm intended.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    E3 = Thought

    http://folding.stanford.edu/·- Donating some CPU/GPU downtime just might lead to a cure for cancer! My team stats.
  • CJCJ Posts: 470
    edited 2008-04-09 19:11
    I was getting at using pos detector mode, not the edge modes, to measure the high time which can be used quite handily if the proportion of high to low is fairly stable, or if the low pulse duration is stable

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Parallax Forums - If you're ready to learn, we're ready to help.
  • Ken PetersonKen Peterson Posts: 806
    edited 2008-04-09 20:14
    If the measurement of your sensor is represented by the frequency of negative pulses, why don't you use negative edge detect and read the counter after a fixed time delay? Then PHSA would be proportional to your frequency.

    If you need to read faster, then you can measure the duration between pulses using POS (not POS EDGE) detect mode and doing a waitpin function to wait for the input to go negative. On each negative pulse you read PHSA and set it back to zero. Now PHSA would be proportional to the period, IOW inversely proportional to the frequency.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    The more I know, the more I know I don't know.· Is this what they call Wisdom?
Sign In or Register to comment.