Transmitter

'pic16f690 and PBP Joystick 38400baud only transmit 900 bytes/sec,30 servo pulses a sec.

'GPS is also transmitted from plane on same xbees 500 bytes/sec 2.5hz of GPS data

'xbee 900 38400baud, transparent mode,broadcast,RO=0,MT=0(broadcast multi transmit... default is 3 so it defaults to sending each packet 3 times )reduces data transmitted by xbee,this is what allowed us to up the transmission with out delays
DEFINE OSC 8 '8Mhz
DEFINE HSER_SPBRG 51 'BRGH-1 BRG16-1 GIVES LESS THAN 0.5% ERROR
define HSER_TXSTA 24h
define HSER_RCSTA 90h
DEFINE HSER_CLROERR 1 'Clear overflow error automatically
OSCCON=%01110000 '8 Mhz
'define varables

synchbyte con $ff
trottle var byte
rudder var byte
elavator var byte
aileron var byte
trottletrim var byte
ruddertrim var byte
elavatortrim var byte
ailerontrim var byte
trottle_adc con 1
rudder_adc con 0
elavator_adc con 2
aileron_adc con 4
trottletrim_adc con 0
ruddertrim_adc con 5
elavatortrim_adc con 6
ailerontrim_adc con 10


'switch variables
switch1 var porta.5
switch2 var porta.4
switch3 var porta.3
switch4 var portc.5
switch1out var byte
switch2out var byte
switch3out var byte
switch4out var byte
highlevel con 1
lowlevel con 0
TRISA = %11111111 'set porta to all input all trisa registers setup as input on power up/reset
TRISC = %11111111 'set portc to all input
TRISB.4 = 1 'set portb.4 to input ignore the rest
ANSEL = %11110111 'set analog an0,an1,an2,an4,an5,an6,an7
ANSELH = %00000100 'set analog an10
'ansel and anselh to select the channel on690
BAUDCTL=%00001000 'BRG16 SET TO 1 and with the 51 this gives 38400baud
SPBRGH = 0 'clears the upper byte of spbrg

Pause 1000 'wait 1 second to let every thing get started.
CM1CON0 = 0
CM2CON0 = 0


mainloop:
'joysticks outputs
adcin trottle_adc, trottle 'read the trottle adc channnel 0

Pause 1
trottle_out: hserout [$ff,$0,trottle]

pause 2


if switch1=highlevel then
switch1out=$fe
else
switch1out=$00
endif
PAUSE 1
hserout[$ff,$04,switch1out]
Pause 2

adcin rudder_adc, rudder 'read the rudder

adcin ruddertrim_adc,ruddertrim 'read the rudder trim
ruddertrim=ruddertrim >> 2
if ruddertrim =<31 then rudder_trim_subtract_it
goto rudder_trim_add_it
rudder_out: PAUSE 1

hserout[$ff,$01,rudder]
pause 2

if switch2=highlevel then
switch2out=$fe
else
switch2out=$00
endif
PAUSE 1
hserout[$ff,$05,switch2out]
pause 2


adcin elavator_adc,elavator 'read the elavator

adcin elavatortrim_adc,elavatortrim
elavatortrim=elavatortrim >> 2
if elavatortrim =<31 then elavator_trim_subtract_it
goto elavator_trim_add_it
elavator_out: PAUSE 1
hserout [$ff,$02,elavator]
Pause 2

if switch3=highlevel then
switch3out=$fe
else
switch3out=$00
endif
PAUSE 1
hserout[$ff,$06,switch3out]
pause 2
adcin aileron_adc,aileron 'read the aileron

adcin ailerontrim_adc,ailerontrim
ailerontrim=ailerontrim >> 2
if ailerontrim =<31 then aileron_trim_subtract_it
goto aileron_trim_add_it
aileron_out: PAUSE 1
hserout[$ff,$03,aileron]
pause 2
if switch4=highlevel then
switch4out=$fe
else
switch4out=$00
endif
PAUSE 1
hserout[$ff,$07,switch4out]
pause 2


goto mainloop 'back to the start of it for ever.


'trims addition and subtraction and limit settings

rudder_trim_subtract_it: ruddertrim=ruddertrim ^ %00011111
if rudder>=ruddertrim then
rudder=rudder-ruddertrim
else
rudder=$00
endif
goto rudder_out

rudder_trim_add_it: ruddertrim=ruddertrim-32
if 255-ruddertrim>=rudder then
rudder=rudder+ruddertrim
else
rudder=$fe
endif
goto rudder_out

elavator_trim_subtract_it: elavatortrim=elavatortrim ^ %00011111
if elavator>=elavatortrim then
elavator=elavator-elavatortrim
else
elavator=$00
endif
goto elavator_out

elavator_trim_add_it: elavatortrim=elavatortrim-32
if 255-elavatortrim>=elavator then
elavator=elavator+elavatortrim
else
elavator=$fe
endif
goto elavator_out


aileron_trim_subtract_it: ailerontrim=ailerontrim ^ %00011111
if aileron>=ailerontrim then
aileron=aileron-ailerontrim
else
aileron=$00
endif
goto aileron_out

aileron_trim_add_it: ailerontrim=ailerontrim-32
if 255-ailerontrim>=aileron then
aileron=aileron+ailerontrim
else
aileron=$fe
endif
goto aileron_out

 

 

Receiver works like the polulo servo receiver but ignores dropped bytes and does not lockup.

XBEE configured the same way as the transmitter,transparent mode,broadcast,RO=0,MT=0

DEFINE OSC 16     'need to change the INC file when setting this up.
DEFINE  HSER_BAUD     38400
define HSER_TXSTA  24h
define HSER_RCSTA  90h
DEFINE  HSER_CLROERR 1   'Clear overflow error automatically
SPBRGH = 0    'clears the upper byte of spbrg

synchbyte        con $ff
servonumber     var byte
servodata       var word
servodata_in     var byte
buffer          var byte
buffer1         var byte

TRISC = %00000000   ;  set portc as outputs
CM1CON0 = 0
CM2CON0 = 0
portc=0

   Hserin[buffer,buffer1]  'leftover bytes that where missed not in synch with stream of data
  main     
       
        hserin[wait($ff),servonumber,servodata_in]
        servodata=servodata_in*4
        if servonumber=$00 then goto servonumber0
        if servonumber=$01 then goto servonumber1
        if servonumber=$02 then goto servonumber2
        if servonumber=$03 then goto servonumber3
        if servonumber=$04 then goto servonumber4
        if servonumber=$05 then goto servonumber5
        if servonumber=$06 then goto servonumber6
        if servonumber=$07 then
           goto servonumber7
          else
           goto main
        endif
        goto main
servonumber0
       
        portc=%00000001 
         Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main

servonumber1
       
        portc=%00000010 
         Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main
servonumber2
        portc=%00000100 
          Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main
servonumber3
        portc=%00001000 
         Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main
servonumber4
        portc=%00010000 
         Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main
servonumber5
        portc=%00100000 
         Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main
servonumber6
        portc=%01000000 
         Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main
servonumber7
        portc=%10000000 
       Pause 1
       PAUSEUS SERVODATA
        portc=%00000000
    GoTo main

 

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • 3D Robotics
    If you want to post code, please explain what it is and then post it as a file with the file icon. This doesn't mean anything to anyone.
This reply was deleted.

Activity