Shop OBEX P1 Docs P2 Docs Learn Events
Conditional Compilation For Pulsout — Parallax Forums

Conditional Compilation For Pulsout

NWUpgradesNWUpgrades Posts: 292
edited 2009-10-23 22:44 in BASIC Stamp
Is it possible to create a Conditional Compilation for the Pulsout function? This would surely simplify running the BS2 code for the BoeBot, etc on a BS2sx chip. Just a thoght...

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-23 04:04
    Sure. Along with the Baud constants, just add an adjustment factor. For the BS2 models, the unit is either 2us or 0.8us. To get the PULSOUT argument, you'd need to divide the time in us by either 2 or 8/10. Alternatively you could multiply by 2/4 (1/2) or 5/4 (10/8). In the various condition compilation choices, you'd define a constant "adjFactor" as either 2 (for 2us) or 5 (for 0.8us) and make each PULSOUT like "PULSOUT <pin>,(<time us>*adjFactor)>>2".

    You could use the conditional compilation directives right around the PULSOUT statement(s), but you'd end up with a very very difficult to read, but otherwise correct and efficient version.
  • NWUpgradesNWUpgrades Posts: 292
    edited 2009-10-23 21:55
    Do you by chance have an example? Math has never been my strongest point.
  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-23 22:44
    All the math is in that previous reply. If you're using pin 13, you'd declare some name like "myPin" with

    myPin PIN 13

    then you'd add either

    adjFactor CON 2 ' PULSOUT unit is 2us

    or

    adjFactor CON 5 ' PULSOUT unit is 0.8us

    to the various groups of conditional declarations.

    If you want to produce a 1.5ms pulse, you'd put

    PULSOUT myPin, (1500 * adjFactor) >> 2
Sign In or Register to comment.