Interupts
Posted: Fri Aug 01, 2014 6:45 am
I'm looking to implement two different ways of controlling my nxt motor shield;
a) just drive the motor via pwm and read speed in rpm from the rotary encoder (done - http://wiki.micropython.org/contributedmodules/nxtmotor)
b) tell the motor to move a certain number of degrees, tracking it with the rotary encoder and stopping when it has
The first method uses an irq_rising on the pin that one of the encoder/tacks (well that's what lego call it) is connected to and reads the other tack Pin hi/lo status.
The second ideally should read both the rising and falling edge of one of the tacks (and do the same read of the other tack to determine direction) to give 1deg rather than 2 deg precision (notwithstanding motor spin-down), but that would either require;
- changing the interrupt function depending on mode, but once a function's been associated there's no direct way to remove, replace or update it (I've tried passing in a variable that directs to a function to pyb.ExtInt and then later changing the function the variable points at ... but that doesn't work)
- registering a single function, but one that can differentiate having been called by a rising or falling edge ... but I can't see a way to achieve that on an interrupt set as IRQ_RISING_FALLING)
Anyone got any ideas or suggestion on potential workarounds?
a) just drive the motor via pwm and read speed in rpm from the rotary encoder (done - http://wiki.micropython.org/contributedmodules/nxtmotor)
b) tell the motor to move a certain number of degrees, tracking it with the rotary encoder and stopping when it has
The first method uses an irq_rising on the pin that one of the encoder/tacks (well that's what lego call it) is connected to and reads the other tack Pin hi/lo status.
The second ideally should read both the rising and falling edge of one of the tacks (and do the same read of the other tack to determine direction) to give 1deg rather than 2 deg precision (notwithstanding motor spin-down), but that would either require;
- changing the interrupt function depending on mode, but once a function's been associated there's no direct way to remove, replace or update it (I've tried passing in a variable that directs to a function to pyb.ExtInt and then later changing the function the variable points at ... but that doesn't work)
- registering a single function, but one that can differentiate having been called by a rising or falling edge ... but I can't see a way to achieve that on an interrupt set as IRQ_RISING_FALLING)
Anyone got any ideas or suggestion on potential workarounds?