Shop OBEX P1 Docs P2 Docs Learn Events
Why is X := clkfreq * 15/10_000 not the same as X := clkfreq *150/100_000 ? — Parallax Forums

Why is X := clkfreq * 15/10_000 not the same as X := clkfreq *150/100_000 ?

SteveWoodroughSteveWoodrough Posts: 190
edited 2010-03-13 17:12 in Propeller 1
I'm on page 156 of the PEK Lab Fundamentals.···One of the lab tasks is to modify a program (below) to make a servo signal of 1.3 and 1.7 ms.·
·
Below is the full program with the lines in question bolded.·
·
Everything below works fine.· I can make the continuous rotation servo move CW and CCW but the speed resolution is poor.· 15 for stop, 14 and 13 one way, 16, 17 the other.··When I tried to make the servo signal resolution·more fine, it does not work.· My approach is the change tHa := clkfreq * 15/10_000··to··tHa := clkfreq * 150/100_000.· In theory the ratio is the same and in theory I should pick up more resolution.·
·
What concept am I missing?
Thanks
Steve
···

·''From Parallax Inc. Propeller Education Kit - 6: Counter Modules and
''Circuit Aplications
{{
TestDualPWM.spin
Demonstrates using two counter modules to send a dual PWM signal.
The cycle time is the same for both signals, but the high times are independent of
each other.
}}
CON
··
· _clkmode = xtal1 + pll16x················· ' System clock → 80 MHz
· _xinfreq = 5_000_000
PUB TestPwm | tc, tHa, tHb, t
· ctra[noparse][[/noparse]30..26] := ctrb[noparse][[/noparse]30..26] := %00101···· ' Counters A and B → NCO single-ended
· ctra[noparse][[/noparse]8..0] := 4··························· ' Set pins for counters to control
· ctrb[noparse][[/noparse]8..0] := 6······
· ctra[noparse][[/noparse]14..9] := 5··························· ' Set pins for counters to control
· ctrb[noparse][[/noparse]14..9] := 7·
· frqa := frqb := 1························· ' Add 1 to phs with each clock tick
························
·· dira [noparse][[/noparse]4..7]~~
· tC := clkfreq *2_0/1_000····························· ' Set up cycle time
· tHa := clkfreq * 1_5/10_000·························· ' Set up high times for both signals
· tHb := clkfreq* 1_7/10_000
· t := cnt·································· ' Mark current time.
·
· repeat···································· ' Repeat PWM signal
··· phsa := -tHa···························· ' Define and start the A pulse
··· phsb := -tHb···························· ' Define and start the B pulse
··· t += tC································· ' Calculate next cycle repeat
··· waitcnt(t)······························ ' Wait for next cyc

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Recent Project Videos:

http://www.youtube.com/watch?v=jI79Xsm_Kyk&feature=channel_page

Cool Cars:
http://www.youtube.com/watch?v=SLnPhYKZCqo&feature=channel_page
http://www.youtube.com/watch?v=d2xGkYN4v7g&feature=channel_page

Comments

Sign In or Register to comment.