Shop OBEX P1 Docs P2 Docs Learn Events
Converting PST number input to useable integers with waitcnt — Parallax Forums

Converting PST number input to useable integers with waitcnt

fingeraefingerae Posts: 15
edited 2009-04-24 17:09 in Propeller 1
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-24 04:34
    Why are you displaying "fan_speed2" when your input value is in "fan_speed"?

    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.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-24 04:36
    For the control characters, look at the source code for FullDuplexSerialPlus. There's a list of the control characters at the beginning and lots of small PUB methods that just send a single control character (along with a comment describing what they do).

    Post Edited (Mike Green) : 4/24/2009 4:43:13 AM GMT
  • fingeraefingerae Posts: 15
    edited 2009-04-24 04:49
    Thank you.· fan_speed2 was a typo.· That is not in the original code.· The application is a PWM drive for a DC motor. A longer pulse period will be fine.· I tried to code it this way, because it is for my students.· I was trying to emphasize PWM operation in the simplest Propeller code operation.· Thanks as always Mike!
  • simonlsimonl Posts: 866
    edited 2009-04-24 14:36
    PST's control codes can be found in PST: click the "Prefs..." button, then the "Function" tab.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    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 wink.gif
  • fingeraefingerae Posts: 15
    edited 2009-04-24 17:09
    Thanks so much!· You rock simonl!· It's always·the simple things that get you.· It looks like you're into aviation.· Do you have any recommendations for a low cost altimiter for hobby aircraft?
Sign In or Register to comment.