PDA

View Full Version : Has anyone had trouble with ctra mode %01010?



shanghai_fool
01-23-2009, 06:17 PM
I am trying to count frequency using last example in AN001 but it seems to be erratic.
The input is from my scope reference·(1 kHz @3.6v p-p) but the reading varies substantially ~1500.
Prop is running 80MHz and I do mode %01000 (pos pulse width) just great.

When I use a variable input squarewave, it doesn't follow it.

I only added a waitcnt after the display loop otherwise I couldn't get a clear reading.
I know I'm missing something but I can't see it. I will try again toorrow with fresh eyes.

Donald
·

Beau Schwabe (Parallax)
01-24-2009, 12:21 AM
shanghai_fool,

I wouldn't think that the 1kHz from your scope would show that much jitter, but a value of 1500 indicates about a 2% error.

Can you attach the code that you are using to get these readings?

You say that %01000 works great... what about mode %01100 (NEG detector) ... or even mode %01110 (NEGEDGE detector) What are the results from these modes?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

shanghai_fool
01-24-2009, 07:59 AM
Beau,

I am using the example in the tech note. I have also tried· %01110· with the same results.


''Demonstration of the counter used as a frequency counter
CON
_clkmode = xtal1 + pll16x
_XinFREQ = 5_000_000
OBJ
txt : "PC_Interface"
VAR
long ctr, frq
PUB Go | freq
txt.start(31,30)
cognew(@entry, @freq)

repeat
txt.out($00) 'clear the screen
txt.dec(freq) 'display the value (in Hz)
waitcnt(cnt + clkfreq) 'added to make display readable
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 + 23 '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

shanghai_fool
01-24-2009, 11:17 AM
It still is not working well. I really need this. I want to measure brushless motor rpm. I have one phase of the ESC connected through a low-pass filter/comparator which produces a very clean square wave. I need to do 2 of these with one cog. The counters are the only way to do this effectively and accurately.

Is there some additional input filtering needed on the input pin? I would think anything with <12.5ns risetime would be sufficient.

Donald

Bob Lawrence (VE1RLL)
01-24-2009, 11:20 AM
@ shanghai_fool

I've only played with Prop Asm a few times so feel free to ignore me if I'm off base here but I did notice the following difference from AN001

cognew(@entry, @freq) ' your code

cognew(@entry, freq) ' AN001

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Aka: CosmicBob

shanghai_fool
01-24-2009, 11:41 AM
The AN001 text is incorrect. The example included with the zip file is OK. The parameter to be passed to the cog is @freq, the address of the variable which becomes PAR in the pasm code. Maybe the text was written hastily. It also includes a variables "frq" and "ctr" which are not used.
Thanks anyway.

Beau Schwabe (Parallax)
01-24-2009, 02:19 PM
shanghai_fool (http://forums.parallax.com/member.php?u=54678),

I tried·the code you posted on my end and I get values ranging from 1006 to 1018 on·my scope.

The only thing I did differently was change the input pin from 23 to 7 ... and I have the routine displaying to·a TV.



ctra_ long %01010 << 26 + 23 'mode + APIN


·to read....


ctra_ long %01010 << 26 + 7 'mode + APIN


·Is your scope ground connected to the Propeller ground?· Is pin 23 on your board connected to anything else?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Paul Rowntree
01-24-2009, 02:31 PM
Shanghai; have you tried a Schmitt on the input?
I think we are working on the same type of project, and I would appreciate some details of your interface. I am trying to drive a hard disk motor with a prop and L293D, and while it can drive the motor, starting from a dead stop requires my spinning the shaft by hand. I am running out of ideas, but will try sine waves next and a set of three TIP120 circuits. Are you controlling the brushless with the prop? How do you do it?

Cheers!
Paul Rowntree

shanghai_fool
01-24-2009, 03:29 PM
@Beau,
That may be part of my problem. I do not use the VGA but I have the parts mounted and there are some resistors connected there.

@ Paul,
I think you may have hit the nail on the head and is exactly what I am thinking after looking closer at my "square wave". My scope is a 25MHz. Rigol and having been used to a 150MHz scope, I did not pay enough attention to the rise time which is way too long. Even the scope test output is too long. There is way too much time in "no man's land" at Vcc/2. Even driving with the op-amp comparator output is too slow. I need some Schmitt triggers on the input but, unfortunately tomorrow starts New Year's and no one will be working for a couple of weeks so I can't get any parts.

I am controlling the motors with a common RC type ESC (electronic speed control) but I want to keep the rpm's close as well. I know the exact static thrust each prop has relative to the rpm. I can effectively "weigh" the aircraft at hover. The 2 motors will be controlled via gyro/accellerometer/Kalman filter. If I could phase lock sync the motors, I would probably try that also but I don't want to design the ESC's.

My filter circuit is a standard Chebychev 3 pole low pass to get rid of the ESC's high freq noise. It puts out what I thought was a clean signal except the AD8594's slew rate isn't quite good enough. I will try to pick up some 74LVC14A's first chance I get.

I was trying to figure out how to read 2 counters at the same time with accuracy but decided to wait 1/2 second for one and the 1/2 sec for the other. I'm still not sure how accurate I can get though. I may also try measuring pulse width instead. At 5000 RPM, a 12 pole motor produces 1 kHz signal.

While I am waiting, I will workl on other aspects of my project. Like a really accurate receiver pulse width detector that works with PCM of PPM pulses. The current one in OBEX isn't quite accurate enough for PCM.

Happy Lunar New Year everyone and welcome year of the OX.

Donald

Beau Schwabe (Parallax)
01-24-2009, 11:13 PM
shanghai_fool (http://forums.parallax.com/member.php?u=54678),

It shouldn't matter if you are using a VGA,TV, or serial to view the reported data... the TV just happened to be my "Debug of Choice" at the moment while I was running your code.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe (mailto:bschwabe@parallax.com)

IC Layout Engineer
Parallax, Inc.

Tracy Allen
01-25-2009, 03:24 AM
The important thing is not so much the rise time of the signal as it is that the signal make a one-way transition through the threshold. Sometimes in lieu of a Schmitt, a resistor in parallel with a diode, and placed between between the signal and the input pin, will act as an asymmetric filter along with the pin's input capacitance. Be careful for ground loops though. You don't want any noise on the ground line to appear in series with your signal.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)