Old PIC, simple PIC and I'm learning so im still on the most basic one that i could find documentation for.
What I am trying to do is measure and mix the signals from a 2 channel RC unit receiver to operate a skid steer (tank) with the one stick. Like a wheel chair but with analogue control, or at least kind of.
For a "go or no" set up, i think its easy, if both channels are maxed that means that its full throttle in one direction, ie forward left or back right depending on how its set up. if the first is maxed and the second is in the middle position its full forward.
What I would like to do is to add speed control to the equation but im stumped how i am going to do that unless I add another channel and use my pic output speed control with the timer perhaps (meh)
Since my code got stuffed, I reverted back to an older code which measures the output of 2 channel RC unit and uses the LEDS to display the result from each channel on its side of the pic in binary.
Can someone suggest where i can go next with my code to make this work please?
EDIT: Wow this is old code, I won't be using the channel error checking as im using a 2.4ghz digital reciever which "should" be better with noise.
err quick run down on the code.
Check if pin0 is high on portA, when it is high, count to 1ms then start incrementing a counter till the pin goes low or the max is reached,
repeat for pin1 then apply the outputs. output should be 1 to 255 if memory serves, doesn't need to be any where near that fine tuned.
What I am trying to do is measure and mix the signals from a 2 channel RC unit receiver to operate a skid steer (tank) with the one stick. Like a wheel chair but with analogue control, or at least kind of.
For a "go or no" set up, i think its easy, if both channels are maxed that means that its full throttle in one direction, ie forward left or back right depending on how its set up. if the first is maxed and the second is in the middle position its full forward.
What I would like to do is to add speed control to the equation but im stumped how i am going to do that unless I add another channel and use my pic output speed control with the timer perhaps (meh)
Since my code got stuffed, I reverted back to an older code which measures the output of 2 channel RC unit and uses the LEDS to display the result from each channel on its side of the pic in binary.
Can someone suggest where i can go next with my code to make this work please?
EDIT: Wow this is old code, I won't be using the channel error checking as im using a 2.4ghz digital reciever which "should" be better with noise.
err quick run down on the code.
Check if pin0 is high on portA, when it is high, count to 1ms then start incrementing a counter till the pin goes low or the max is reached,
repeat for pin1 then apply the outputs. output should be 1 to 255 if memory serves, doesn't need to be any where near that fine tuned.
Code:
;/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
;written by: D.J.K /
;date: 01/06/09 \
;version: 1. /
;file saved as: ESC01.asm \
;for PIC: P16F84A /
;clock frequency:5mhZ \
;XT: 20mhz HS /
; \
;\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
;PROGRAM NOTES : mesure two chanel from RC reciever and display
;pulse width as leds on portB
list P=16F84A
include "p16f84a.inc"
;=============
;Declarations:
__config _HS_OSC & _WDT_OFF & _PWRTE_ON
cblock 0Ch
CH1V
WST0
WST1
WST2
WST3
CH1T1
CH1T2
CH1T3
CH1T4
CHSELECT
CH1T21
CH1T22
CH2V
CH2T1
CH2T2
CH2T3
CH2T4
CH2T21
CH2T22
endc
org 000h
goto Start
; org 004h
; goto Inturupt
org 100h
;==============
;Program start
Start:
goto Init
Init:
clrf PORTA ;resets input/output ports
clrf PORTB
bsf STATUS,RP0 ;select bank 1
movlw b'00000011' ;pin 0 as input
movwf TRISA ;
movlw b'00000000' ;all port B as Outputs
movwf TRISB
movlw b'00000000' ;no prescaling
movwf OPTION_REG ;
bcf STATUS,RP0 ;selects bank 0
movlw b'00000000' ;no interupts
movwf INTCON
clrf WST0
clrf WST1
clrf WST2
Main:
; btfss CHSELECT,0
goto CH1Start
; goto CH2Start
CH1Start:
bsf CHSELECT,0
btfss PORTA,0 ;wait for pulse to start
goto CH1Start ;loop till pin is high
call Waste1ms ;Wait nearly 1ms
clrf CH1V
goto CH1 ;count after 1ms
CH1:
; movlw b'01111110'
; movwf CH1V
btfss PORTA,0 ;is the pin still high?
goto CH2Start ;no, output the number to leds
call Waste ;wait nearly 1/128th of signal range
incfsz CH1V,f ;yes, increase the count
goto CH1
decf CH1V,f
goto CH1
CH2Start:
bcf CHSELECT,0
btfss PORTA,1 ;wait for pulse to start
goto CH2Start ;loop till pin is high
call Waste1ms2 ;Wait nearly 1ms
clrf CH2V
goto CH2 ;count after 1ms
CH2:
; movlw b'10000000'
; movwf CH2V
btfss PORTA,1 ;is the pin still high?
goto CH1set ;no, Output the number to leds
call Waste5 ;wait nearly 1/128th of signal range
incfsz CH2V,f ;yes, increase the count
goto CH2
decf CH2V,f
goto CH2
CH1set:
; movlw B'00110011'
; movwf CH1V
movf CH1T3,W ;keep the last 4 signals in banks
movwf CH1T4 ;take the first 2 numbers from each other
movwf CH1T22 ;then take the results from each other
movf CH1T2,W ;if there is nothing left for both equations
movwf CH1T3 ;then put the consifmed signal to PORTB
movf CH1T1,W
movwf CH1T2
movwf CH1T21
movf CH1V,W
movwf CH1T1
movf CH1T1,w
subwf CH1T22,f
btfss STATUS,Z
goto CH2Set
movf CH1T3,w
subwf CH1T21,f
btfss STATUS,Z
goto CH2Set
movf CH1T21,w
addwf CH1T22,f
btfss STATUS,Z ;check if remainder is zero
goto CH2Set ;if last 4 signals are not the same, look for a new signal
goto Output1
movf CH1V,w ;move variable to working
movwf PORTB ;output number to leds PORTB = binary display
goto CH2Set
Waste:
movlw d'3' ;rest time between incrementing signal
movwf WST0 ;variable, 10 leaves with range of 199 to 128
Waste2: ;with RC unit tested
decfsz WST0,f ;4 with 6 gives 17 to 250
goto Waste2
Return
Waste1ms:
movlw d'6' ;rest time before counting signal
movwf WST2
Waste1:
decfsz WST1,f
goto Waste1
decfsz WST2,f
goto Waste1
Return
Output1:
btfsc CH1V,7
goto Ovr128
btfsc CH1V,6
goto Ovr64
btfsc CH1V,5
goto Ovr32
btfsc CH1V,4
goto Out16
goto Out0
Ovr32
btfsc CH1V,4
goto Out48 ;+16?
goto Out32 ;then start number
Ovr64
btfsc CH1V,5 ;+32?
goto Ovr96
btfsc CH1V,4 ;+16?
goto Out80
goto Out64 ;then start number
Ovr96
btfsc CH1V,4 ;+16?
goto Out112
goto Out96 ;then start number
Ovr128
btfsc CH1V,6 ;+64?
goto Ovr192
btfsc CH1V,5 ;+32?
goto Ovr160
btfsc CH1V,4 ;+16?
goto Out144
goto Out128 ;then start number
Ovr160
btfsc CH1V,4 ;+16?
goto Out176
goto Out160 ;then start number
Ovr192
btfsc CH1V,5 ;+32?
goto Ovr224
btfsc CH1V,4 ;+16?
goto Out208
goto Out192 ;then start number
Ovr224
btfsc CH1V,4
goto Out240 ;+16?
goto Out224 ;then start number
Out0
bcf PORTB,0
bcf PORTB,1
bcf PORTB,2
bcf PORTB,3
; movlw b'00000000'
; movwf PORTB
goto CH2Set
Out16
bsf PORTB,1
bcf PORTB,1
bcf PORTB,2
bcf PORTB,3
; movlw b'00000001'
; movwf PORTB
goto CH2Set
Out32
bcf PORTB,0
bsf PORTB,1
bcf PORTB,2
bcf PORTB,3
; movlw b'00000010'
; movwf PORTB
goto CH2Set
Out48
bsf PORTB,0
bsf PORTB,1
bcf PORTB,2
bcf PORTB,3
; movlw b'00000011'
; movwf PORTB
goto CH2Set
Out64
bcf PORTB,0
bcf PORTB,1
bsf PORTB,2
bcf PORTB,3
; movlw b'00000100'
; movwf PORTB
goto CH2Set
Out80
bsf PORTB,0
bcf PORTB,1
bsf PORTB,2
bcf PORTB,3
; movlw b'00000101'
; movwf PORTB
goto CH2Set
Out96
bcf PORTB,0
bsf PORTB,1
bsf PORTB,2
bcf PORTB,3
; movlw b'00000110'
; movwf PORTB
goto CH2Set
Out112
bsf PORTB,0
bsf PORTB,1
bsf PORTB,2
bcf PORTB,3
; movlw b'00000111'
; movwf PORTB
goto CH2Set
Out128
bcf PORTB,0
bcf PORTB,1
bcf PORTB,2
bsf PORTB,3
; movlw b'00001000'
; movwf PORTB
goto CH2Set
Out144
bsf PORTB,0
bcf PORTB,1
bcf PORTB,2
bsf PORTB,3
; movlw b'00001001'
; movwf PORTB
goto CH2Set
Out160
bcf PORTB,0
bsf PORTB,1
bcf PORTB,2
bsf PORTB,3
; movlw b'00001010'
; movwf PORTB
goto CH2Set
Out176
bsf PORTB,0
bsf PORTB,1
bcf PORTB,2
bsf PORTB,3
; movlw b'00001011'
; movwf PORTB
goto CH2Set
Out192
bcf PORTB,0
bcf PORTB,1
bsf PORTB,2
bsf PORTB,3
; movlw b'00001100'
; movwf PORTB
goto CH2Set
Out208
bsf PORTB,0
bcf PORTB,1
bsf PORTB,2
bsf PORTB,3
; movlw b'00001101'
; movwf PORTB
goto CH2Set
Out224
bcf PORTB,0
bsf PORTB,1
bsf PORTB,2
bsf PORTB,3
; movlw b'00001110'
; movwf PORTB
goto CH2Set
Out240
bsf PORTB,0
bsf PORTB,1
bsf PORTB,2
bsf PORTB,3
; movlw b'00001111'
; movwf PORTB
goto CH2Set
CH2Set:
; movlw B'00110011'
; movwf CH2V
movf CH2T3,W ;keep the last 4 signals in banks
movwf CH2T4 ;take the first 2 numbers from each other
movwf CH2T22 ;then take the results from each other
movf CH2T2,W ;if there is nothing left for both equations
movwf CH2T3 ;then put the consifmed signal to PORTB
movf CH2T1,W
movwf CH2T2
movwf CH2T21
movf CH2V,W
movwf CH2T1
movf CH2T1,w
subwf CH2T22,f
btfss STATUS,Z
goto Main
movf CH2T3,w
subwf CH2T21,f
btfss STATUS,Z
goto Main
movf CH2T21,w
addwf CH2T22,f
btfss STATUS,Z ;check if remainder is zero
goto Main ;if last 4 signals are not the same, look for a new signal
goto Output2
movf CH2V,w ;move variable to working
movwf PORTB ;Output number to leds PORTB = binary display
goto Main
Waste5:
movlw d'3' ;rest time between incrementing signal
movwf WST0 ;variable, 10 leaves with range of 199 to 128
Waste4: ;with RC unit tested
decfsz WST0,f ;4 with 6 gives 17 to 250
goto Waste4
Return
Waste1ms2:
movlw d'6' ;rest time before counting signal
movwf WST2
Waste3:
decfsz WST1,f
goto Waste1
decfsz WST2,f
goto Waste3
Return
Output2:
btfsc CH2V,7
goto Ovr2128
btfsc CH2V,6
goto Ovr264
btfsc CH2V,5
goto Ovr232
btfsc CH2V,4
goto Out216
goto Out20
Ovr232
btfsc CH2V,4
goto Out248 ;+16?
goto Out232 ;then start number
Ovr264
btfsc CH2V,5 ;+32?
goto Ovr296
btfsc CH2V,4 ;+16?
goto Out280
goto Out264 ;then start number
Ovr296
btfsc CH2V,4 ;+16?
goto Out2112
goto Out296 ;then start number
Ovr2128
btfsc CH2V,6 ;+64?
goto Ovr2192
btfsc CH2V,5 ;+32?
goto Ovr2160
btfsc CH2V,4 ;+16?
goto Out2144
goto Out2128 ;then start number
Ovr2160
btfsc CH2V,4 ;+16?
goto Out2176
goto Out2160 ;then start number
Ovr2192
btfsc CH2V,5 ;+32?
goto Ovr2224
btfsc CH2V,4 ;+16?
goto Out2208
goto Out2192 ;then start number
Ovr2224
btfsc CH2V,4
goto Out2240 ;+16?
goto Out2224 ;then start number
Out20
bcf PORTB,7
bcf PORTB,6
bcf PORTB,5
bcf PORTB,4
; movlw b'00000000'
; movwf PORTB
goto Main
Out216
bsf PORTB,7
bcf PORTB,7
bcf PORTB,6
bcf PORTB,5
; movlw b'10000000'
; movwf PORTB
goto Main
Out232
bcf PORTB,7
bsf PORTB,6
bcf PORTB,5
bcf PORTB,4
; movlw b'01000000'
; movwf PORTB
goto Main
Out248
bsf PORTB,7
bsf PORTB,6
bcf PORTB,5
bcf PORTB,4
; movlw b'11000000'
; movwf PORTB
goto Main
Out264
bcf PORTB,7
bcf PORTB,6
bsf PORTB,5
bcf PORTB,4
; movlw b'00100000'
; movwf PORTB
goto Main
Out280
bsf PORTB,7
bcf PORTB,6
bsf PORTB,5
bcf PORTB,4
; movlw b'10100000'
; movwf PORTB
goto Main
Out296
bcf PORTB,7
bsf PORTB,6
bsf PORTB,5
bcf PORTB,4
; movlw b'01100000'
; movwf PORTB
goto Main
Out2112
bsf PORTB,7
bsf PORTB,6
bsf PORTB,5
bcf PORTB,4
; movlw b'11100000'
; movwf PORTB
goto Main
Out2128
bcf PORTB,7
bcf PORTB,6
bcf PORTB,5
bsf PORTB,4
; movlw b'00010000'
; movwf PORTB
goto Main
Out2144
bsf PORTB,7
bcf PORTB,6
bcf PORTB,5
bsf PORTB,4
; movlw b'10010000'
; movwf PORTB
goto Main
Out2160
bcf PORTB,7
bsf PORTB,6
bcf PORTB,5
bsf PORTB,4
; movlw b'01010000'
; movwf PORTB
goto Main
Out2176
bsf PORTB,7
bsf PORTB,6
bcf PORTB,5
bsf PORTB,4
; movlw b'11010000'
; movwf PORTB
goto Main
Out2192
bcf PORTB,7
bcf PORTB,6
bsf PORTB,5
bsf PORTB,4
; movlw b'00110000'
; movwf PORTB
goto Main
Out2208
bsf PORTB,7
bcf PORTB,6
bsf PORTB,5
bsf PORTB,4
; movlw b'10110000'
; movwf PORTB
goto Main
Out2224
bcf PORTB,7
bsf PORTB,6
bsf PORTB,5
bsf PORTB,4
; movlw b'01110000'
; movwf PORTB
goto Main
Out2240
bsf PORTB,7
bsf PORTB,6
bsf PORTB,5
bsf PORTB,4
; movlw b'11110000'
; movwf PORTB
goto Main
END
Last edited: