Hi,
As some of you know I’ve choosed to control my LM Phoenix with a RC controller. The main reason for why I choosed RC is probably caused by my some defect LM PS2 controller. My Phoenix are very hard to control with the PS2.
Reading the RC channels from the RC receiver is pretty easy with the pulsin command. Here is a example of the code I used:
[code]Read RC pulses
;
RCInput:
pulsin RCch01,0, pwmInput01
pwmInput01 = (pwmInput01 min RCpwmMIN) max RCpwmMAX
pulsin RCch03,0, pwmInput03
pwmInput03 = (pwmInput03 min RCpwmMIN) max RCpwmMAX
pulsin RCch05,0, pwmInput05 'There is a 7,5mS gap between ch05 and ch06
Mode1 = False
Mode2 = False
Mode3 = False
if pwmInput05 < 980 then
Mode1 = True
elseif ((pwmInput05 > 1510) & (pwmInput05 < 1522))
Mode2 = True
else
Mode3 = True
endif
pulsin RCch06,0, pwmInput06
pulsin RCch02,0, pwmInput02
pwmInput02 = (pwmInput02 min RCpwmMIN) max RCpwmMAX
pulsin RCch04,0, pwmInput04
pwmInput04 = (pwmInput04 min RCpwmMIN) max RCpwmMAX
return[/code]
Reading all these channels take some valuable time from the BAP code, thats probably the reason for why I can’t match Xan’s awesome speed
So I’ve been experimenting with using an extra BAP24 for reading the RC channels. This is the code I wrote for the CO-BAP:
[code];RC Reader
;
;Read 6 RC channels continiously
;When receiveing an interrupt pulse on IRQ1 (Pin8) it sends all channels out on P11 via serout (IntHandler)
;
;[CONST]
TRUE con 1
FALSE con 0
;--------------------------------------------------------------------
;[SERIAL CONNECTIONS]
Serial_OUT con P11 ;Output pin on BotBoard
;--------------------------------------------------------------------
;[RC Controller]
RCch01 con P0
RCch02 con P1
RCch03 con P2
RCch04 con P3
RCch05 con P4
RCch06 con P5
RCpwmMAX con 1850
RCpwmMIN con 1150
;--------------------------------------------------------------------
;RC variable
pwmCH01Input var word
pwmCH02Input var word
pwmCH03Input var word
pwmCH04Input var word
pwmCH05Input var word
pwmCH06Input var word
pwmCH01old var word
pwmCH02old var word
pwmCH03old var word
pwmCH04old var word
pwmCH05old var word
pwmCH06old var word
CH01_OK var bit
CH02_OK var bit
CH03_OK var bit
CH04_OK var bit
CH05_OK var bit
CH06_OK var bit
ONINTERRUPT IRQ1INT,IntHandler
PMR1.bit5 = 1 'define as IRQ input pin IRQ1, IRQ1 = pin8
ENABLE IRQ1INT
main:
;Read ch 01:
CH01_OK = FALSE
pulsin RCch01,0, pwmCH01Input
pwmCH01Input = (pwmCH01Input min RCpwmMIN) max RCpwmMAX
CH01_OK = TRUE
pwmCH01old = pwmCH01Input
;Read ch 03:
CH03_OK = FALSE
pulsin RCch03,0, pwmCH03Input
pwmCH03Input = (pwmCH03Input min RCpwmMIN) max RCpwmMAX
CH03_OK = TRUE
pwmCH03old = pwmCH03Input
;Read ch 05:
CH05_OK = FALSE
pulsin RCch05,0, pwmCH05Input
CH05_OK = TRUE
pwmCH05old = pwmCH05Input
;Read ch 06:
CH06_OK = FALSE
pulsin RCch06,0, pwmCH06Input
CH06_OK = TRUE
pwmCH06old = pwmCH06Input
;Read ch 02:
CH02_OK = FALSE
pulsin RCch02,0, pwmCH02Input
pwmCH02Input = (pwmCH02Input min RCpwmMIN) max RCpwmMAX
CH02_OK = TRUE
pwmCH02old = pwmCH02Input
;Read ch 04:
CH04_OK = FALSE
pulsin RCch04,0, pwmCH04Input
pwmCH04Input = (pwmCH04Input min RCpwmMIN) max RCpwmMAX
CH04_OK = TRUE
pwmCH04old = pwmCH04Input
goto main
IntHandler
'check if the interrupt “destroyed” the pulsin reading:
If CH01_OK & CH02_OK & CH03_OK & CH04_OK & CH05_OK & CH06_OK then
goto AllOK
elseif NOT CH01_OK 'if so, fix it:
pwmCH01Input = pwmCH01old
elseif NOT CH02_OK
pwmCH02Input = pwmCH02old
elseif NOT CH03_OK
pwmCH03Input = pwmCH03old
elseif NOT CH04_OK
pwmCH04Input = pwmCH04old
elseif NOT CH05_OK
pwmCH05Input = pwmCH05old
elseif NOT CH06_OK
pwmCH06Input = pwmCH06old
endif
AllOK:
;send pwm data to host BAP28:
serout Serial_OUT, i57600, [pwmCH01Input.lowbyte,pwmCH01Input.highbyte,|
pwmCH02Input.lowbyte,pwmCH02Input.highbyte,|
pwmCH03Input.lowbyte,pwmCH03Input.highbyte,|
pwmCH04Input.lowbyte,pwmCH04Input.highbyte,|
pwmCH05Input.lowbyte,pwmCH05Input.highbyte,|
pwmCH06Input.lowbyte,pwmCH06Input.highbyte]
resume[/code]
Since I’m no programming expert I didn’t find a way to enter/send words, therefore I used the .lowbyte and .highbyte. Does anyone know a better way to this?
If the interrupt occour when the BAP are in the middle of a pulsin command the current pwm reading will be corrupt, thats the reason for why I uses a CHXX_OK. And restore the previous (old) value.
So far this code works very well. And this is the simple code you’ll need to add into your main BAP:
[code]high IRQ_OUT ;Send the interrupt pulse to the CO-BAP
low IRQ_OUT
serin PWM_IN, i57600, [pwmInput01.lowbyte,pwmInput01.highbyte,|
pwmInput02.lowbyte,pwmInput02.highbyte,|
pwmInput03.lowbyte,pwmInput03.highbyte,|
pwmInput04.lowbyte,pwmInput04.highbyte,|
pwmInput05.lowbyte,pwmInput05.highbyte,|
pwmInput06.lowbyte,pwmInput06.highbyte][/code]
I’m thinking of making a very little simple board to hold the extra BAP24. I think the BB2 can supply this with power too? I measured that the BAP24 + RC receiver needed about 130 mAh.
Any comments are appreciated.