Converting PST number input to useable integers with waitcnt
fingerae
Posts: 15
I am using FullDuplexSerialPlus.· My end goal is to be prompted for a number on the Propeller Serial Terminal (PST), enter the number on a keyboard, and use number with the WAITCNT function.· The following code does not work the way I think it should indicated by the comments.· fan_speed displays correctly, but arithmetic operations using it indicate that it is not compatiblewith integer math.· I have tried several perterbations of floating point arithmetic, round(), and trunc(), but it appears that the waitcnt function requires something else to give me the desired result. Any thoughts?· (As a side note, does anyone have a reference for the proper characters for the PST for things like carriage returns, clear screen, etc?)· I sincerely appreciate any help.· Thanks.
· SER.tx($00)············································ · 'Clear the screen
· SER.str(string("Enter the first integer fan speed between 0 and 255."))············ 'Display string
· SER.str(string($0D))····································'Display carriage return
· fan_speed := SER.GetDec···························· 'Input fan speed from user input on screen
· SER.str(string("fan speed = "))······················'Display text
· SER.dec(fan_speed2)···································'Display fan speed
· waitcnt(fan_speed + cnt)·····························'Wait "fan speed" counts
· SER.tx($00)············································ · 'Clear the screen
· SER.str(string("Enter the first integer fan speed between 0 and 255."))············ 'Display string
· SER.str(string($0D))····································'Display carriage return
· fan_speed := SER.GetDec···························· 'Input fan speed from user input on screen
· SER.str(string("fan speed = "))······················'Display text
· SER.dec(fan_speed2)···································'Display fan speed
· waitcnt(fan_speed + cnt)·····························'Wait "fan speed" counts
Comments
Remember that "fan_speed" is in system clock ticks which, with an 80MHz system clock speed,
is 12.5ns. Your delay ranges from 0 to roughly 3us, not something you'd notice. In addition, the
execution time of the WAITCNT statement itself is much greater than this and the WAITCNT will
miss the time requested, so it will wait for something on the order of 50 seconds no matter what
you enter.
You need a longer delay time. It depends on what you want to want the "fan speed" to mean.
As an example, if you want to enter the delay time in milliseconds, you'd have:
waitcnt((clkfreq/1000)*(fan_speed+1) + cnt)
This would establish a minimum delay of 1ms, not anything you'd notice, but it would avoid the
50 some second delay. You'd have a delay time of somewhere between 1ms and 256ms for
values entered between 0 and 255.
Post Edited (Mike Green) : 4/24/2009 4:43:13 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheers,
Simon
www.norfolkhelicopterclub.com
You'll always have as many take-offs as landings, the trick is to be sure you can take-off again