slviajero / tinybasic

A BASIC interpreter for Arduino, ESP, RP2040, STM32, Infineon XMC and POSIX with IoT and microcontroller features.
GNU General Public License v3.0
203 stars 31 forks source link

While you are working on ISR #31

Closed EncomLab closed 1 year ago

EncomLab commented 1 year ago

Morning Stefan! The other way in which I am currently using interrupts for the robot platform is to handle the output from optical rotary encoders. I currently just use this to get a step count by assigning a ENCODERA or ENCODERB command to a variable and assigning the encoder a pin number. Then I just use the variable in an IF statement to issue a STOP command to the motors.

` //MOTOR AND ENCODER FUNCTIONS //soft reset void interruptFunctionSR() { xbreak(); }

//encoder a volatile uint16_t interruptCountA = 0; void interruptFunctionA() { interruptCountA++; }

void xencodera() { x = pop(); short int encoderaPin; encoderaPin = pinNum(x);

pinMode(encoderaPin, INPUT_PULLUP); enableInterrupt(encoderaPin, interruptFunctionA, CHANGE);

push(interruptCountA);

}

//encoder b volatile uint16_t interruptCountB = 0; void interruptFunctionB() { interruptCountB++; }

void xencoderb() { x = pop(); short int encoderbPin; encoderbPin = pinNum(x);

pinMode(encoderbPin, INPUT_PULLUP); enableInterrupt(encoderbPin, interruptFunctionB, CHANGE);

push(interruptCountB);

}`

slviajero commented 1 year ago

Looks very good. That is exactly following the logic of the interpreter. I need to think about how to generalise this. BASIC is not the ideal language to handle interrupts because there is no way to define procedures / call backs.

Am 18.10.2022 um 11:56 schrieb Encom Lab @.***>:

Morning Stefan! The other way in which I am currently using interrupts for the robot platform is to handle the output from optical rotary encoders. I currently just use this to get a step count by assigning a ENCODERA or ENCODERB command to a variable and assigning the encoder a pin number. Then I just use the variable in an IF statement to issue a STOP command to the motors.

`//MOTOR AND ENCODER FUNCTIONS //soft reset void interruptFunctionSR() { xbreak(); }

//encoder a volatile uint16_t interruptCountA = 0; void interruptFunctionA() { interruptCountA++; }

void xencodera() { x = pop(); short int encoderaPin; encoderaPin = pinNum(x);

pinMode(encoderaPin, INPUT_PULLUP); enableInterrupt(encoderaPin, interruptFunctionA, CHANGE);

push(interruptCountA);

}

//encoder b volatile uint16_t interruptCountB = 0; void interruptFunctionB() { interruptCountB++; }

void xencoderb() { x = pop(); short int encoderbPin; encoderbPin = pinNum(x);

pinMode(encoderbPin, INPUT_PULLUP); enableInterrupt(encoderbPin, interruptFunctionB, CHANGE);

push(interruptCountB);

}`

— Reply to this email directly, view it on GitHub https://github.com/slviajero/tinybasic/issues/31, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSY56DMPGX5ZBTOT6M7XP3WDZX6HANCNFSM6AAAAAARH43FFU. You are receiving this because you are subscribed to this thread.

slviajero commented 1 year ago

Just for info, I now have released the first code with built-in interrupt code. It is documented in the MANUAL, the command EVENT is doing the interrupt stuff. Still working to improve it.