Shop OBEX P1 Docs P2 Docs Learn Events
Problem/question about frequency period counter — Parallax Forums

Problem/question about frequency period counter

turbosupraturbosupra Posts: 1,088
edited 2012-03-08 11:08 in Propeller 1
Hi,

I am using the jm_freqin object, specifically the period method that counts cycles between a pin seeing a high and the next time it sees another high. My problem is that I need to sample faster than the method return value is being updated, so I get duplicate values. My dilemma is that the value update rate changes independently and randomly as far as the propeller is concerned, so a fixed sampling rate will not work and sometimes the previous and current values being identical are valid method return values as well.

I can't come up with a way to code around this so that I know I'm reading an updated value, and not a duplicate because of the sampling rate. Does anyone have any ideas?

Thanks for reading.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-08 10:12
    Here's what I would do. Modify Jon's period routine like so:
    pub period
    
    '' Returns period of input waveform
    
      result := fcCycles
      fcCycles~ 
    
    If, when you call it, it returns zero, you will know that it hasn't updated since the previous call.

    -Phil
  • turbosupraturbosupra Posts: 1,088
    edited 2012-03-08 11:08
    You are the man!

    Thank you so much Phil, a simple solution that works great.
    Here's what I would do. Modify Jon's period routine like so:
    pub period
    
    '' Returns period of input waveform
    
      result := fcCycles
      fcCycles~ 
    
    If, when you call it, it returns zero, you will know that it hasn't updated since the previous call.

    -Phil
Sign In or Register to comment.