Du har rätt, jag använder AtS2313 till ett fartreglag, och styrningen sköts med två servo kopplat direkt från mottagaren.
Koden är inte skriven i assembler utan skriven i Basic [bacom]. Men den har några inslag av assembler trots allt, rutinen för att ta reda på pulsbredden är skriven i assembler.
Källkod:
$crystal = 10000000
Dim B As Word
Dim A As Word
Dim C As Word
Dim Dbf As Word
Dim Pp As Word
Dim Px As Word
Dim Ss As Byte
Dim Xx As Single
Dim Zz As Single
Config Pind.5 = Input 'set-up button
Config Pind.6 = Input 'receiver input
Config Pinb.5 = Output 'center led
Config Pinb.6 = Output 'forward led
Config Pinb.7 = Output 'armed led
Config Pinb.3 = Output 'motor ouput
Set Portb.5 'turn on center led
Set Portb.6 'turn on forward led
Reset Portb.7 'turn off armed led
'***this sets the PWM drive to 2400Hz***
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Prescale = 8
Config Timer0 = Timer , Prescale = 1024
On Timer0 Mispulse
Do
Debounce Pind.5 , 0 , Center , Sub 'set center value
Loop
Trap:
Do
Debounce Pind.5 , 0 , Forward , Sub 'set full forward value
Loop
Centercheck: 'check for return to center
Gosub Getpulse
If B < Dbf Then
Goto Centercheck
End If
Enable Interrupts
Enable Timer0 'enable missing pulse interrupt
Start Timer0
Wait 1
Set Portb.7 'turn on armed led
Do
Gosub Getpulse 'measure rx input
Gosub Setpulse 'set motor speed
Loop
End
Center: '**calculates center value**
Gosub Getpulse
A = B
Dbf = A - 15
Reset Portb.5 'turn off center led
Goto Trap
Return
Forward: ' **calculates forward value**
Gosub Getpulse
C = B
C = C + 15
Pp = Dbf - C
Reset Portb.6
Goto Centercheck
Return
Setpulse:
If B < C Then 'turns motor on 100% close to full forward
Pwm1a = 255
Goto Done
End If
If B >= Dbf Then 'turns motor off at center
Pwm1a = 0
Goto Done
End If
If B < Dbf Then 'sets motor drive from input signal
Px = Dbf - B
Xx = Px / Pp
If Xx < .05 Then 'this sets a 5% minimum on value
Xx = .05
End If
If Xx > .94 Then 'this sets a max on value at 95%
Xx = 1
End If
Zz = Xx * 255
Ss = Zz
Pwm1a = Ss
Goto Done
End If
Done:
Return
Getpulse: 'measures the RX pulse width
B = 0
Getpulse_1:
sbis pind,6
rjmp getpulse_1
Getpulse_2:
Incr B
sbic pind,6
rjmp getpulse_2
Timer0 = 0 'resets missing pulse timer
Return
Mispulse: 'if two pulses are missed motor turns off
Pwm1a = 0
Return
Jag kan tyvärr inte ta åt mig äran för koden då den är kopierad från ett projekt från AVRfreaks.
ProjectID: 30
Title: Lonnie Trueland
Author: atrueland (alonzo trueland)
Registered at AVRfreaks.net October 08, 2001
www.avrfreaks.net