Frequency Counter Issue on PropRPM Board
deiloohay
Posts: 11
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?
·
''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
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.
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 you
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?
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
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...
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...
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.
In any case, thank you for your help!