Shop OBEX P1 Docs P2 Docs Learn Events
PropBASIC - PULSOUT - low clock speed — Parallax Forums

PropBASIC - PULSOUT - low clock speed

phatallicaphatallica Posts: 64
edited 2013-08-19 15:09 in Propeller 1
Note of caution for PULSOUT with PropBASIC ...
The following code does not work with 5MHz crystal and PLL1X, but does work with PLL2X or higher:
' Use: HCSR04_inch
' --- Pulses TRIG pin for 10us to initiate transmission burst of 40kHz
' --- Reads ECHO pulse to calculate distance
'{$IFUSED HCSR04_inch}
FUNC HCSR04_inch
  PULSOUT TRIG,10             ' initiation pulse
  PULSIN ECHO, 1, __param1    ' measure HIGH time; cannot set timeout, so must wait
  __param1 = __param1 / 148   ' convert to integer inches
  RETURN                      ' returning param1 is implied
ENDFUNC
'{$ENDIF}

The duration of the pulse does not seem to matter, either, as I tried several orders of magnitude. Using PULSOUT with 5MHz just seems to hang-up the code, with the pin HIGH.

I don't see many folks posting code at such low frequency, so maybe I am the only one who has ever noticed this?

Side note - PropBASIC Syntax Guide, Version 0.13, page 8 ... the following is shown to demonstrate syntax:
PULSIN Pin, State, Variable {, Timeout}
In this case, the parameter for Timeout is optional.

It seems that Timeout never actually made it into the feature set of PropBASIC. I don't have a practical need for it, but for some reason once I know that I can't have it, I suddenly want it.

Comments

  • BeanBean Posts: 8,129
    edited 2013-08-17 18:05
    Thanks for the report. I will look into the problem as soon as I can.

    Bean
  • BeanBean Posts: 8,129
    edited 2013-08-19 14:33
    I can confirm your findings.
    The code doesn't actually hang, but it will stop until the hardware counter rolls-over for each microsecond (that could be a LONG time).

    Thanks again for pointing it out and I'll have it fixed in the next release of PropBasic.

    Bean
  • phatallicaphatallica Posts: 64
    edited 2013-08-19 15:09
    Bean wrote: »
    Thanks again for pointing it out and I'll have it fixed in the next release of PropBasic.

    Thanks, Bean.
Sign In or Register to comment.