'Flex IRS Saw positioning ' Low Priority Interrupt on Timer3 overflow ' in Flex used to generate the stepping frequency for the motor ' here it also keeps track of the slide position: sawpos Low_Prior_Interrupt: Timer3_ISR: Context Save ' Save the contents of WREG, STATUS, and BSR Clear PIR2bits_TMR3IF ' Clear the Timer3 interrupt flag. Tim3 = Period ' period wordt bepaald bij ontvangst van een note on Btg Mot_Klok ' portA.5 blueled = sensor1 redled = sensor2 If poweron = 1 Then ' if power is off, the motor will not run. If mot_enable = 0 Then ' this means the motor is running If mot_dir = 0 Then ' saw position monitoring in the interrupt. ' we are running cw, outwards with the saw If sawpos > 0 Then Dec sawpos ' we block off at zero If sensor1 = 1 Then ' running cw and reaching the end Set mot_enable ' stop motor Clear Sawpos ' reset sawpos Motspeed =1 ' reset speed mot_dir = 1 ' inverse direction of rotation: set ccw sollpos = hys_min ' set soll position to away from the sensor period = Freqs[Motspeed] Timvals[2] = time + Dur5[Rampspeed] Clear mot_enable ' restart motor 'sollspeed = 64 ' to be tested value, set at note-on EndIf Else ' ccw running counterclockwize , bending the saw inwards ' so increment motor step counter If sawpos < maxpos Then Inc sawpos ' more efficient coding of the above. If sensor2 = 1 Then ' end sensor reached Set mot_enable ' stop motor maxpos = sawpos ' store value for maxpos mot_dir = 0 ' inverse direction of rotation : set cw sollpos = hys_max Motspeed = 1 period = Freqs[Motspeed] Timvals[2] = time + Dur5[Rampspeed] Clear mot_enable ' restart motor 'sollspeed = 64 EndIf EndIf EndIf EndIf Context Restore ' Restore the contents of WREG, STATUS, and BSR, then exit interrupt ' Retfie ' required? 'Return