Shop OBEX P1 Docs P2 Docs Learn Events
Accurate timing... without timer? [Query] — Parallax Forums

Accurate timing... without timer? [Query]

pwillardpwillard Posts: 321
edited 2008-02-26 00:40 in General Discussion
I have a working project for an audio·frequency counter·completed using an ATMEL AVR but it got me thinking about using an SX28 for the same thing just to see how it could be done.· On the AVR, I made use of the timer interrupt and the ·"counter" mode of the on-chip timers.· Looking at the SX28, I see that the timer absent from the list of features.

If I use a high speed resonator and instead of interrupts·use software delay loops can I count on having reasonably accurate results (to a point)?· I mean accurately enough for say a 20MHZ Frequency Counter.·

I did Google first but frequency counting with SX28·seems to have very·few if any good·examples.



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

There's nothing like a new idea and a warm soldering iron.

Comments

  • PJMontyPJMonty Posts: 983
    edited 2007-10-03 19:38
    Pwillard,

    I think it's going to be pretty hard to get accurate timing u to 20 MHz using a chip running at 50 MHz. Even if you push the SX to 75 MHz, you still don't have a lot of CPU cycles between incoming pulses. At 50 MHz, you have 2.5 CPU cycles between incoming pulses, and at 75 MHz, you have 3.75. I don't see how a software solution is going to work here.

    Thanks,
    PeterM
  • pwillardpwillard Posts: 321
    edited 2007-10-03 19:44
    That was my thought as well after reviewing the datasheet. thanks.

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

    There's nothing like a new idea and a warm soldering iron.
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2007-10-03 20:36
    I agree with PJMonty’s assessment… But do you really need to measure audio signals clear up to 20MHz? shocked.gif

    I think humans can hear to around 20KHz, dogs up around 50KHz and bats clear up to 100Khz or so. Do you really need an audio frequency counter that goes clear up to 20MHz?

    Just wondering.

    - Sparks
  • pwillardpwillard Posts: 321
    edited 2007-10-03 22:19
    Let me clarify that. I only needed audio frequencies for my current project and that's a done deal. I'm working at the extreme crystal speed of my current AVR device so I imagined I could scale the top end up with a processor that could run faster. No big deal... MY SX28 won't go unloved.

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

    There's nothing like a new idea and a warm soldering iron.
  • PJMontyPJMonty Posts: 983
    edited 2007-10-04 05:31
    PWillard,

    Understood. Still, to expect the SX to handle frequencies 1000 times higher than the Atmel chip is kind of over the top. Ten times? Sure. 100? Maybe? 1000? Now you're just being greedy. BTW, I'm just busting your chops when I say that.

    Your task is probably a good job for an FPGA with a really fast clock.

    Thanks,
    PeterM
  • BeanBean Posts: 8,129
    edited 2007-10-04 13:29
    pwillard,
    · Actually I have just recently been working on a similar project.
    · By using the RTCC input with prescaler I was able to count up to 50MHz while running the SX at only 5 MHz.

    DEVICE SX28, OSCXT1, TURBO, STACKX, OPTIONX, BOR26
    FREQ 5_000_000 ' Xtal
     
    ' For fast frequencies (MHz) use RTCC prescaler = 256
    ' Use RTCC prescaler = 1, 2, 4, 8, 16, 32, 64, 128 for slower frequencies
     
    ' Variables
    freqCnt  VAR Word
     
    PROGRAM Start NOSTARTUP
     
    Start:
      DO
        ' Measure frequency at RTCC input pin (300KHz to 50MHz)
        freqCnt = 0
        OPTION = %1110_1000                  ' RTCC on external pin, prescaler = 1:256
        RTCC = 0                             ' This will clear the prescaler too
     
    ' This routine will increament "freqCnt" every 17 cycles until RTCC = 255
    Measure:
        ASM
          INC freqCnt_LSB ' 1                Adjust LSB of freqCnt
          JNZ NoOverflow  ' 2/4              If LSB did NOT overlow then skip
          INC freqCnt_MSB ' 1                Adjust MSB of freqCnt
          JZ Done         ' 2/4              If MSB is now zero, we overflowed (freq too low) quit
          MOV W,RTCC      ' 1                Get current RTCC value
          XOR W,#$FF      ' 1                Does RTCC = 255 ?
          JNZ Measure     ' 2/4              If no, then keep measuring
          JMP Done        ' 3                If yes, then we're done
     
    NoOverflow:
          NOP             ' 1                Needed to keep timing consistent
          MOV W,RTCC      ' 1                Get current RTCC value
          XOR W,#$FF      ' 1                Does RTCC = 255 ?
          JNZ Measure     ' 2/4              If no, then keep measuring
        ENDASM            '                  If yes, then we're done   
    Done:
    
    'Frequency at RTCC input pin = 19200/freqCnt (MHz)
    WATCH freqCnt
    BREAK
     
      LOOP
    END
    
    


    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    My goal is to live forever...Or die trying.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.hittconsulting.com


    Post Edited (Bean (Hitt Consulting)) : 10/4/2007 1:38:08 PM GMT
  • pwillardpwillard Posts: 321
    edited 2007-10-04 13:53
    <clutching my heart with surprise> Wow, that was unexpected!

    I was so dead set on looking to replicate my method used with the AVR that I wasn't looking into any other possibilities...

    Awesome as always Bean!

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

    There's nothing like a new idea and a warm soldering iron.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2007-10-04 15:20
    And, if you are set on timers... The SX48 has two 16bit timers in hardware.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "Everything in the world is purchased by labour; and our passions are the only causes of labor." -- David·Hume (1711-76)········
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • nonnnononnno Posts: 28
    edited 2008-02-25 11:08
    I live in Japan.
    I do not understand English.
    I write this with an interpreter.
    Please allow for a sentence to be strange.
    I use "20MHZxtal" for the next place and measure "50MHZ".
    What does XS do that I am particular about this use for?

    http://www5b.biglobe.ne.jp/~YASUSI/gallery/electronics/061104/061104.htm
  • BeanBean Posts: 8,129
    edited 2008-02-25 14:04
    Kramer said...
    And, if you are set on timers... The SX48 has two 16bit timers in hardware.

    Alas it is not to be...
    The SX48 16-bit timers don't work the same way. You can only measure up to 1/2 the clock frequency EVEN WITH the prescalers.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • BeanBean Posts: 8,129
    edited 2008-02-25 14:07
    nonnno said...
    I live in Japan.
    I do not understand English.
    I write this with an interpreter.
    Please allow for a sentence to be strange.
    I use "20MHZxtal" for the next place and measure "50MHZ".
    What does XS do that I am particular about this use for?

    http://www5b.biglobe.ne.jp/~YASUSI/gallery/electronics/061104/061104.htm
    With a 20MHz xtal, you should be able to measure 50MHz. You will need to set the prescaler to at LEAST 1:8.

    The frequency AFTER the prescaler must be less than 1/2 of the SX clock frequency.

    50.0/8 = 6.25MHz

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • nonnnononnno Posts: 28
    edited 2008-02-25 15:31
    Thank you for an early answer.
    The next part cannot understand me.
    Can you measure a clock of SX to 160MHZ at the time of 20MHZ? .

    The circuit where I took for an example inputs 20MHz into CLKin and inputs it into RA3,RA4 through resistance.
    By a method to send a prescaler and a timer, I decide the most suitable number of partitions I measure frequency in first time, and to be next.
    How much does the best measurement upper limit frequency of such a method become?
    nonnno
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-02-25 15:45
    Bean,
    Can you elaborate why the 16-bit multi-use timers won't do the job while the RTCC can?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PLEASE CONSIDER the following:

    Do you want a quickly operational black box solution or the knowledge included therein?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • BeanBean Posts: 8,129
    edited 2008-02-25 15:53
    I'm not sure. But it must have to do with the way the prescaler work.

    When using the RTCC input the OUTPUT of the prescaler must be less than half of the SX clock, but when using the SX48 timers the INPUT to the prescalers must be less than half the SX clock.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • BeanBean Posts: 8,129
    edited 2008-02-25 15:54
    nonnno said...
    Thank you for an early answer.
    The next part cannot understand me.
    Can you measure a clock of SX to 160MHZ at the time of 20MHZ? .

    The circuit where I took for an example inputs 20MHz into CLKin and inputs it into RA3,RA4 through resistance.
    By a method to send a prescaler and a timer, I decide the most suitable number of partitions I measure frequency in first time, and to be next.
    How much does the best measurement upper limit frequency of such a method become?
    nonnno
    From what I remember when I was playing around with this about 50MHz is the absolute maximum regardless of what the SX is clocked at.

    Bean.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2008-02-25 16:19
    Thanks, I'll try to investigate the prescaler differences.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PLEASE CONSIDER the following:

    Do you want a quickly operational black box solution or the knowledge included therein?······
    ···················· Tropically,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • nonnnononnno Posts: 28
    edited 2008-02-26 00:40
    As for me, "SX was surprised to be able to have pwm of high speed many ch".
    Because I was able to obtain "SX28AC/SS" several, I looked for a document.
    I wandered in web and found here and found words of "Bean.".
    I still touch it in "SX", and there is hardly knowledge at the start.
    (Data of the greatest input frequency of RTCC are short.)
    According to the data sheet which the microchip of the contents which I examined gives, it is next. It "is FIGURE 17-8:00" "PIC16F627A/628A/648A Data Sheet" "16F648A" "p146" The best frequency is 50MHZ by TIMER0 AND TIMER1 EXTERNAL CLOCK TIMINGS "42=20ns" this.
    I look for a similar document in this.
    When I take the clock source of "SX28AC/SS" not XTAL outside, it is written 50MHZ or 75MHZ and does not become clear which it is.
    I am sad if a prescaler acts on only 1/2, 37.5MHz of the clock source if it is 75MHZ.
    nonnno
Sign In or Register to comment.