' Name : mixer.BAS ' Author : Christopher Good ' Notice : Copyright (c) 2012 ' : All Rights Reserved ' Date : 9 Apr 2012 ' Version : 1.0 ' Notes : Free source code. Compile with Proton IDE Lite (also free). Program your PIC with IC-Prog (also free). ' ' Pin8 = Ground - tie to common, connect to pin 1 via .1MF cap ' Pin7 = GPIO.0 - i/o - not used ' Pin6 = GPIO.1 - i/o - output RC PWM signal X ' Pin5 = GPIO.2 - i/o - output RC PWM signal Y ' Pin4 = GPIO.3 - input only - input RC PWM signal A - tie to RC signal via 4.7k ohm resistor ' Pin3 = GPIO.4 - i/o - input RC PWM signal B - tie to RC signal via 4.7k ohm resistor ' Pin2 = GPIO.5 - i/o - not used ' Pin1 = Vcc - tie to +5v, connect to pin 8 via .1MF cap ' Use Input A as timing source ' - gyro A will be set to normal output rate ' Once Input A has been read, do a single pulsin for Input B ' - gyro B will be set to high rate (digital) output so any of its outputs can be read ' Output mixed values at this point ' loop Device 12C508 Config INTRC_OSC, MCLRE_OFF, WDT_OFF, CP_OFF ' set config fuses OPTION_REG.5 = 0 ' clock source internal Dim PulsA As Byte Dim PulsB As Byte Dim BaseA As Byte Dim BaseB As Byte Dim OutX As Word Dim OutY As Word Clear BaseA = 150 BaseB = 150 ReadA: PulsA = PulsIn GPIO.3, High ' pin 4 If PulsA > 50 And PulsA < 250 Then BaseA = PulsA ' valid signal received ReadB: PulsB = PulsIn GPIO.4, High ' pin 3 If PulsB > 50 And PulsB < 250 Then BaseB = PulsB ' valid signal received OutPulse: ' set the bounds for A and B inputs If BaseA < 75 Then BaseA = 75 If BaseA > 225 Then BaseA = 225 If BaseB < 75 Then BaseB = 75 If BaseB > 225 Then BaseB = 225 ' compute mixed output OutX = BaseA + BaseB - 150 OutY = BaseA + 150 - BaseB ' set the bounds for X and Y outputs If OutX < 75 Then OutX = 75 If OutX > 225 Then OutX = 225 If OutY < 75 Then OutY = 75 If OutY > 225 Then OutY = 225 ' output each mixed signal Low GPIO.1 Low GPIO.2 PulsOut GPIO.1, OutX PulsOut GPIO.2, OutY GoTo ReadA ' keep looping