Shop OBEX P1 Docs P2 Docs Learn Events
Frequency Counter Issue on PropRPM Board — Parallax Forums

Frequency Counter Issue on PropRPM Board

deiloohaydeiloohay Posts: 11
edited 2008-04-02 01:16 in Propeller 1
Because the proprpm board has a composite video on board, i modified the example code in the following way:
·


''Demonstration of the counter used as a frequency counter
CON
······· _clkmode = xtal1 + pll16x
······· _XinFREQ = 5_000_000
OBJ
······· 'txt : "VGA_Text"
······· txt··· : "tv_text"
······· 'term··· : "tv_terminal"
······· 'num : "numbers"
VAR
······· long ctr, frq, numm
PUB Go | freq
······· txt.start(12)
······· cognew(@entry, @freq)
······· repeat
········· txt.out($00)················· 'clear the screen
········· txt.dec(freq)················ 'display the value (in Hz)
········· waitcnt(80_000_000 + cnt)
DAT
······· org
entry·· mov···· ctra, ctra_············ 'establish mode and start counter
······· mov···· frqa, #1··············· 'increment for each edge seen
······· mov···· cnt_, cnt·············· 'setup time delay
······· add···· cnt_, cntadd
:loop·· waitcnt cnt_, cntadd··········· 'wait for next sample
······· mov···· new, phsa·············· 'record new count
······· mov···· temp, new·············· 'make second copy
······· sub···· new, old··············· 'get delta
······· mov···· old, temp·············· 'set next delta's base
······· wrlong· new, par
······· jmp···· #:loop
ctra_·· long··· %01010 << 26 + 0······· 'mode + APIN
cntadd· long··· 80_000_000············· 'wait 1 second, answer in Hz
cnt_··· res···· 1
new···· res···· 1
old···· res···· 1
temp··· res···· 1


·
I cannot seem to get a number on the screen that is anything like the frequency.· I have tried both using a tone generator and also a manual switch bringing the pin· to Vcc temporarily, the normal connection is 10k to ground.
·
The input pin is looking for a positive edge?· press and hold the switch and the output goes from 0 to 12 or 13 then back to zero.· two quick clicks and the number is up in the 20's.· i expected 2 quick clicks that happened in a 1 second window to return 2hz.· or possibly 2 consecutive readings of 1hz if each click fell into different sampling windows.·
·
is there something obviously wrong with what i'm doing?

Comments

  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-27 00:37
    You should expect something like this with a manual switch if it does not have a debounce circuit. The switch contacts will bounce around giving multiple readings. Otherwise your code looks fine.
  • deiloohaydeiloohay Posts: 11
    edited 2008-03-27 00:53
    Point taken on the de-bounce....

    How about with the signal generator? I tried a 3.3V signal connected directly to p0 and ground, tried again with a 10k resistor between p0 and ground as well, tried a third time with a 1uF non-polorized cap in series with the signal and the 10k resistor going from p0 to ground. Always got a reading of 13000-14000 with a 4500hz test tone, tried wtih a 7500hz test tone and the readings bounced around in the 11000-13000 range.
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-27 01:15
    Sig gen--->---Prop Pin
    
    Sig gen--->---0---/\/\/\---GND
                         |
                         |--------Prop Pin
    
    Sig gen--->-||-0---/\/\/\---GND
                          |
                          |--------Prop Pin
    


    If I understand correctly these are the three configurations you tried? (Assuming that you have the grounds for the prop and signal gen connected)

    Do you have a cro that you can check the signal with?

    Your first reading will be wrong because old will have a value in it when it gets copied from the hub but you probably don't need to worry about that.

    One suggestion. You can use clkfreq instead of the 80,000,000 and this will handle changes in clock frequency for yousmile.gif
  • deiloohaydeiloohay Posts: 11
    edited 2008-03-27 01:38
    The signal gen gnd was connected to the prop gnd each time. There was a 10k resistor in between p0 and gnd in the last 2 cases. Never a series input resistor though (just the series input cap)...

    1uF 10k
    sig gen--->--||
    /\/\/\/\/\-GND
    |
    |
    Prop Pin




    I used the parallax usb oscilliscope to check the signal.

    Good call on the use of clkfreq! Thanks!

    Would you recommend the use of a LPF for the frequencies of interest?
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-27 02:20
    A LPF wouldn't be a bad idea but this isn't the problem that you are having. If you have a look at your results when you put the frequency up your count goes down which is the opposite of what should happen so there is something else going on. It would also appear that your tests with the switch are giving what you would expect so it gets even weirder.

    Where did you check the signal, right at the prop or where you put the signal into the board? I had a look at the schematic for the board and I couldn't see anything hooked up to P0 so I don't think that it will be a problem.

    Are you feeding in a square wave or a sine wave? If it is a sine wave it is possible that with the frequency so low the zone between a high and low (0.3Vdd to 0.6Vdd) is causing problems. This is only a thought that may not be right and really needs commenting on by someone more experienced. Anyway, if you are putting in a sine wave try a square wave and see if it makes any difference.

    I had another look at you code and can't see any problems with it.

    And I should have said welcome to the forums smile.gif
  • deiloohaydeiloohay Posts: 11
    edited 2008-03-29 14:13
    Thank you!

    The code above is minimally modified code from the frequency counter. I saw another thread where someone was using almost the same code to make a frequency counter that used a 2x20 LCD, who was counting much higher frequencies successfully...

    I modified the code to use the composite video out as the display for two reasons:

    I have the propRPM board
    I have a dell monitor that can display the composite video as a picture-in-picture source.

    I have been measuring the signal right at the input, p0. I am using the parallax usb scope to measure.

    The signal source is originating from a program called SoundArb, which is intended to make your sound card into an aribitrary waveform generator. The sound card alone couldnt get the 3.3v signal cleanly, but the headphone amp in the PC speakers could get it up to the right level. That is the source. I have tried both sine and square wave inputs. The square and triangle waves didnt look nearly as clean as the sine on the scope.

    I will try a comparitor buffering stage, input vs 1.65v. With the control mode for positive edge triggering, should it matter if the input is a sine or square wave? Could this circuit be picking up higer frequency noise from the SoundArb program? This is why I though the LPF may be helpful...
  • deiloohaydeiloohay Posts: 11
    edited 2008-03-29 20:53
    Tried it again with a Sine, Square, Trainge and Sawtooth input...

    Tried again with Rin = 2.2k and a 1u non-polorized cap across p0 and gnd...

    A 100hz tone is returning numbers around 32000 +/- about 500...
  • deSilvadeSilva Posts: 2,967
    edited 2008-03-29 21:52
    deiloohay,
    520 x 480 - 28K
  • deiloohaydeiloohay Posts: 11
    edited 2008-03-30 00:05
    I used the R and C in reversed positions, as recommended by a few sites to create a debouncing circuit...
  • stevenmess2004stevenmess2004 Posts: 1,102
    edited 2008-03-30 06:42
    I tested your code by using the timers in the main cog to output a 100hz square wave on pin 0 and it worked fine. So you must have something wrong with your hardware somewhere.

    Can you run the attached program without anything connected to pin0 and tell us the results. If it runs and displays 100 on the screen than it is a problem with your signal or what you have connected to the pin. Otherwise it is a problem with your prop.

    You will need to remove the .txt from the file.
  • deiloohaydeiloohay Posts: 11
    edited 2008-04-02 01:16
    The code you attached works, and even connecting an output in to an input pin via a 100R it works as well. I think the chip needs a more squared off input to detect the positive edge, or a software debounce. When I use the sine wave, there may be some quantization noise that is causing multiple triggers or the chip may not deal with low freqency sine waves that well.

    In any case, thank you for your help!
Sign In or Register to comment.