View Full Version : Conditional Compilation For Pulsout
10-23-2009, 10:30 AM
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...
10-23-2009, 11:04 AM
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.
10-24-2009, 04:55 AM
Do you by chance have an example? Math has never been my strongest point.
10-24-2009, 05:44 AM
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
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