yes i had a look a sparkfun.com and the devices they sell seems very good for what i plan to do next, but for the moment i just want to sense the motion of my head and send it by the ppm signal of my radio to get it on my receiver it should move a servo that move a camera who send the signal to my head mounted display(i know that's a long sentence)

i think that should be enought accurate with the need of a reset button of course.

the ppm sending part is already running with my equipement (just need to put a value from 0 to 1200 in every channel variable)


here is my code:
define OSC 4
OSCCON=%01100000 'pour f88 pic oscillateur interne config marche pas sans ca
output portB.0 'suncro led
output portb.1 'ppm out
input porta.0 'gyro 1
output porta.2 'lcd

ANSEL=%00000001

ADCON1.7=0 ' Left justified bits (10-bits ADRESH=Left ADRESL=Right)
PAUSE 10

ADCON1=%00000000 ' Switch ON an0 A/D's with Vdd as Reference

' A/D 0
ADCON0 = %10000001 ' 20 MHz, Channel 0

'variable for adc
AD0H VAR BYTE ' High Byte 0 - 255
AD0L VAR BYTE ' Low Byte 0 - 255
AD0 VAR WORD ' AD0 word (10 bits)

'need to put fosc2-1 = 100 that means r7 and r8 is i/o et xtal is internal
ch1 var word 'word = 256bit value or 65000 dec val i think
ch2 var word
ch3 var word
ch4 var word
pan var word
tilt var word
ch7 var word
ch8 var word
chsyncro var word
chseparator con 300'296 'with the pauseus it is 0,3ms or 300us
servotest var word
A var word
'change those value for more angles 90° 120°
servomin con 400'700
servomed con 1000 'this is med
servomax con 1600'1700

'channels goes from 0.7ms to 1.7ms min to max
'so that's sounds good with the 0.3ms, entire signal varies from 1ms to 2ms
'neutral without interchannel minipulse is 1,2ms and 1,5ms with minipulse

'i assume that 1200 would be the neutral 1,2ms with the pauseus instruction

'initialise servo position
'put pan servo inthe middle
ch1 = servomed
ch2 = servomed
ch3 = servomed
ch4 = servomed

pan = servomed'is ch5
tilt = servomed'is ch6
ch7 = servomed
ch8 = servomed







gosub lcd_init 'goto lcd init

' Send the ASCII value of B0 followed by a linefeed out Pin0 serially at 19200 baud
SEROUT2 PORTA.2,32,["headtrack ppm adc"]
pause 1000



main:

ReadAD:

ADCON0.2 = 1 ' Start conversion

pauseus 10

AD0H = ADRESH
AD0L = ADRESL
AD0=(AD0H*4)+(AD0L/64)
'ad0=((ad0-460)*10)+ servomed
pan = ad0
SEROUT2 PORTA.2,32,[$A3,$01] 'clear alcd and locate in 0,0
SEROUT2 PORTA.2,32,["value is:",dec pan]
pause 10





'is all servo test mode

'for servotest = servomin to servomax step 5 'start to the min angle and go to max angle progressivly
'ch1 = servotest
'ch2 = servotest
'ch3 = servotest
'ch4 = servotest
'pan = servotest
'tilt = servotest
'ch7 = servotest
'ch8 = servotest
'gosub ppmtrame
'next

'for servotest = servomax to servomin step -5 'start to the min angle and go to max angle progressivly
'ch1 = servotest
'ch2 = servotest
'ch3 = servotest
'ch4 = servotest
'pan = servotest
'tilt = servotest
'ch7 = servotest
'ch8 = servotest
'gosub ppmtrame
'next
'goto main





'send ppm trame and high del0 during chsyncro time
ppmtrame:

'protection against overrange
if ch1 > servomax then ch1 = servomax 'protection cannot go upper than servomax value
if ch1 < servomin then ch1 = servomin 'protection cannot go less than servomin value

if ch2 > servomax then ch2 = servomax 'protection cannot go upper than servomax value
if ch2 < servomin then ch2 = servomin 'protection cannot go less than servomin value

if ch3 > servomax then ch3 = servomax 'protection cannot go upper than servomax value
if ch3 < servomin then ch3 = servomin 'protection cannot go less than servomin value

if ch4 > servomax then ch4 = servomax 'protection cannot go upper than servomax value
if ch4 < servomin then ch4 = servomin 'protection cannot go less than servomin value

if pan > servomax then pan = servomax 'protection cannot go upper than servomax value
if pan < servomin then pan = servomin 'protection cannot go less than servomin value

if tilt > servomax then tilt = servomax 'protection cannot go upper than servomax value
if tilt < servomin then tilt = servomin 'protection cannot go less than servomin value

if ch7 > servomax then ch7 = servomax 'protection cannot go upper than servomax value
if ch7 < servomin then ch7 = servomin 'protection cannot go less than servomin value

if ch8 > servomax then ch8 = servomax 'protection cannot go upper than servomax value
if ch8 < servomin then ch8 = servomin 'protection cannot go less than servomin value

'calcul de chsyncro
'22000-4 for errors = 21996
chsyncro =21996-((chseparator*8)+ch1+ch2+ch3+ch4+pan+tilt+ch7+ch8-10)

'start sending the ppm frame:
high portb.0 'begining of the syncro del is on
high portb.1
pauseus chsyncro
low portb.1
low portb.0 'ending of the syncro del is off
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus ch1
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus ch2
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus ch3
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus ch4
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus pan
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus tilt
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus ch7
low portb.1
pauseus chseparator 'should be 3us low state between channels
high portb.1
pauseus ch8
low portb.1
pauseus chseparator 'should be 3us low state between channels
'stop sending the frame
'return
goto main



'the lcd routine initialisation
lcd_init:
SEROUT2 PORTA.2,32,[$A3,$01] 'clear alcd and locate in 0,0
SEROUT2 PORTA.2,32,[$A1,2,0] 'locate in x,y
SEROUT2 PORTA.2,32,[$A3,$0A] 'stop blinking cursor
'SEROUT2 porta.1,32,[$A3,$0B] 'blink cursor
SEROUT2 PORTA.2,32,[$A3,$0C] 'hide cursor
'SEROUT2 PORTA.1,32,[$A3,$0E] 'show cursor
return

end

fefenin