I've been working on a stepper motor library which calculates timer periods on the fly during acceleration.
I'm currently limited to about 600 pulses/second on each of three motors; past that I run out of the micropython.schedule() queue. I'm calling micropython.schedule() to handle a floating point expression after each timer interrupt.
I'm trying to use the Viper emitter to get better speed out of the ISR. The 'micropython.native' emitter worked OK but I need more speed.
The problem that I'm running into is this: During execution I get an exception from the interrupt handler that looks like this:
Code: Select all
uncaught exception in Timer(8) interrupt handler
TypeError: can't convert float to int
uncaught exception in Timer(13) interrupt handler
TypeError: can't convert float to int
uncaught exception in Timer(4) interrupt handler
TypeError: can't convert float to int
So I'm at a loss as to what exactly is causing this complaint.
My ISR looks like this:
Code: Select all
@micropython.viper
def _compute_new_speed(self, t):
self._step_pin.value(int(1))
# are we at the target speed yet?
self._at_speed = False
if bool(self._decelerating):
self._at_speed = ((int(self._direction) == int(self._target_direction)) \
and (int(self._speed) <= int(self._target_speed)))
if int(self._n) >= int(0): # we've hit int(0) speed; check for a change in direction
# will print after ISR
# micropython.schedule(self._cached_debug, self._cached_msg2)
self._direction = int(self._target_direction)
self._decelerating = False
if int(self._direction) == DIRECTION_CW:
self._direction_pin.value(int(1))
self._reverse_direction_pin.value(int(0))
else:
self._direction_pin.value(int(0))
self._reverse_direction_pin.value(int(1))
else:
self._at_speed = bool(int(self._speed) >= int(self._target_speed))
if bool(self._at_speed):
# micropython.schedule(self._cached_debug, self._cached_msg)
# self.pulse_debug_pin()
self._n = int(0)
self._speed = int(self._target_speed)
self._position = int(self._position) + int(self._direction) # update position
# set the timer period
if int(self._target_speed) != int(0):
self._cn = int(int(TIMER_FREQUENCY) // int(self._target_speed))
t.period(int(self._cn) - int(1))
t.callback(self._cached_update_position)
else:
# stop timer output (and callbacks)
t.deinit()
self._cn = int(0)
return
# update speed and timer period
self._speed = int(int(TIMER_FREQUENCY) // int(self._cn))
t.period(int(self._cn) - int(1))
# update position
self._position = int(self._position) + int(self._direction)
# update _cn and _n after ISR:
micropython.schedule(self._cached_update_cn, None)
self._step_pin.value(int(0))
Thanks!