Da geht's um zwei steppermotoren, deren Geschwindigkeit in
1mS/ schritten zu regeln sind. die details werden dich nicht interessieren, aber die sache mit dem timer kann man erkennen
Code:'=============================================== ' Timer0 Prescale for 1mS Interrupt '============================================== Config Timer0 = Timer , Prescale = 64 'Timer 1mS (8MHZ) Const Tmr_c_preload = 131 'Timer 1mS (8MHZ) On Timer0 Interrupt_ticker .... ....bla, bla, .... '=============================================== ' M A I N L O O P '============================================== Do If Irptflag = 1 Then Irptflag = 0 Gosub Stepptick1 Gosub Stepptick2 End If Loop End '=============================================== ' M A I N L O O P E N D '=============================================== '=============================================== ' Timer 0 interrupt '=============================================== Interrupt_ticker: Timer0 = Tmr_c_preload Irptflag = 1 Return '=============================================== ' Control Stepper '=============================================== Stepptick1: If Steppcountleft > 0 Then Decr Steppcountleft Else If Steppspeedleft <> 0 Then Portc.3 = 0 ' clock low Absi = Abs(steppspeedleft) Steppcountleft = 100 - Absi Portc.3 = 1 ' clock high End If End If Return Stepptick2: If Steppcountrite > 0 Then Decr Steppcountrite Else If Steppspeedrite <> 0 Then Portc.2 = 0 ' clock low Absi = Abs(steppspeedrite) Steppcountrite = 100 - Absi Portc.2 = 1 ' clock high End If End If Return
Lesezeichen