Shop OBEX P1 Docs P2 Docs Learn Events
Using a Frequency meter? — Parallax Forums

Using a Frequency meter?

rwgast_logicdesignrwgast_logicdesign Posts: 1,464
edited 2012-05-10 15:20 in Propeller 1
Ok so I started reading through the BOE pdf file tonight. Im doing the exercise for flashing an LED @1Hz. I just got this new meter that has a
a cheapy 1mhz frequency counter built in. I set the probes up in parallel and Im totally not getting the results on the meters display that I
excpected! Then I took the ground probe off and got .998 which is pretty close to 1hz. So when you measure frequency your only suppose to use
the hot probe? Aslo is the little bit of error i.e. .998 not 1Hz due to the meter or the crystals ppm being a bit off? Here is the code
CON
    _xinfreq = 5_000_000                     
    _clkmode = xtal1 + pll1x
    
PUB flashAt1Hz


  dira[0] := 1
  repeat
    outa[0] := 1
    waitcnt(clkfreq/4 + cnt)   '' Turn LED on for 1/4 second
    outa[0] := 0
    waitcnt(clkfreq/4*3 + cnt) '' Turn LED off for 3/4 second

Comments

  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-05-09 23:08
    well now same code same everything, ground probe connected or disconnected im getting 59.9Hz??????????
  • jmgjmg Posts: 15,183
    edited 2012-05-09 23:09
    I just got this new meter that has a cheapy 1mhz frequency counter built in.

    It may be expecting a +/- signal, try a series CAP, or create a 1/2 VCC virtual ground.
    Also check the Meter's spec, the very basic ones, can be as bad as 1.5% precision on Frequency.
    Your result is 0.2%; too large for a Crystal deviation.

    A 'proper' meter, will easily deliver single digit ppm and 7-8+ digits per second.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-05-09 23:14
    I payed 35 bucks at home depot it a commercial electric, no manual ill google the model for a pdf, at leat.99 is in the balpark, I don't understand why I'm getting close to 60hz now
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-09 23:19
    rwgast_... wrote:
    Aslo is the little bit of error i.e. .998 not 1Hz due to the meter or the crystals ppm being a bit off?
    It's due to the overhead in your code. Try it this way:
    PUB flashAt1Hz | time
    
      dira[0] := 1
      time := cnt
      repeat
        outa[0] := 1
        waitcnt(time += clkfreq/4)   '' Turn LED on for 1/4 second
        outa[0] := 0
        waitcnt(time += clkfreq/4*3) '' Turn LED off for 3/4 second
    

    In your original code, the time required to compute the waitcnt argument and to set the outputs was added to the period. The new code eliminates that overhead by including it the timed period.

    -Phil
  • Heater.Heater. Posts: 21,230
    edited 2012-05-09 23:47
    That 60Hz is the frequency of the AC power in the states.
    Your meter is picking it up "from the air". Or it is getting in due improper grounding.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-05-09 23:51
    Ok so usually what is the best way to probe for frequency with a dmm? Jmgs ideas seem a bit exreem I would think most dmms do this the same way witout ading caps or vgrounds
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-05-10 03:04
    ok phil ive been looking at your code trying to wrap my head around what your doing, im not sure what the pipe operator does, but im thinking that really has no bearing here?

    basically your saying cnt=cnt + clckfreq which is what im assuming is the true fix. so if cnt was at 40,000 now its at 80,000 plus the freqency. this is somehow accounting for clockcycles which have already passed during the code execution? im sry could you please be a little more verbose about whats going on. dealing with clockcycles on this level is a very new concept to me and one which i know i need to get a very good grasp on if i want to write the kind of software i aspire to write for the prop.

    by the way im sry if the above post sounded a little rude or something, this meter is just frustrating me and theres no manual! im having a hell of a time understanding why it gave the correct results the first time and then went off and gave me something totally diffrent under the same conditions..
  • JLockeJLocke Posts: 354
    edited 2012-05-10 06:16
    ok phil ive been looking at your code trying to wrap my head around what your doing, im not sure what the pipe operator does, but im thinking that really has no bearing here?
    Are you talking about the line
    PUB flashAt1Hz | time ?
    The '|' separates the function name from the list of local variables ('time' is a local variable, only accessible to this function). This is from the Propeller Manual v1.1 (page 208):

    1) Local variable separator: appears immediately before a list of local variables on a PUB or PRI declaration. See PUB, page 182 and PRI, page 181.
    2) Bitwise OR: used in expressions. See Bitwise OR ‘|’, ‘|=’ on page 165.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-05-10 07:32
    ued thats what i was talking about. i just started learning spin last night so im not too familiar with any syntax not derived from a launguage i dont already know. i figured the pipe operator was just something to do with the variabels in the function and didnt have anything to do with the acual changes to the code to make the timing acurate.

    so then exactly why double cnt before the division? like i said i understand it is somehow making up for the clock cycles lost during the function but exactly how a perfect cnt+cnt is needed is kind of an enigma to me. my best guess would be is that it takes two full hub passes to complete the function becuase theres two operations, but thats an assumption im very unsure of, since theres no hub communication going on here.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-10 08:51
    rwgast... wrote:
    so then exactly why double cnt before the division?
    I'm not. The "+=" is an addition operator. IOW, time += clkfreq/4 is the same as saying time := time + clkfreq/4. You only need to read cnt once -- before the loop. From there, you just keep incrementing the value read to set the next deadline. That way, all of the computations that contributed to your overhead before are included in the period, rather than being added to it.

    -Phil
  • lardomlardom Posts: 1,659
    edited 2012-05-10 09:04
    @rwgast_logicdesign, Phil's code included the 'add assignment' operator, +=, which compensates for the clock ticks that the code consumes while executing. When you want to eliminate drift due to code execution time and maintain crystal accuracy you can use that operator.
  • rwgast_logicdesignrwgast_logicdesign Posts: 1,464
    edited 2012-05-10 14:53
    Ok, so ive got the meter sorted out now! With my code or phils code I get a .999Hz reading. Now if my meters accuracy was better would I be getting a true 1hz with phils code?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-05-10 15:20
    If your meter has 3 1/2-digit precision +/- 1 digit, the results you're getting are nominally correct. But, yes, a better meter may give you better results.

    -Phil
Sign In or Register to comment.