' ========================================================================= ' ' File...... VEX_Analog_to_Digital.SXB ' Purpose... 12 channel digital demodulator for VEX receiver ' Author.... T'Saavik (based on example code by Jon Williams) ' Please do not contact Mr. Williams for support with this branch. ' E-mail.... sxb@hellspark.com ' Started... 02 MAR 2007 ' Updated... 09 SEPT 2008 ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' Simple program to convert PPM stream from VEX RC receiver to 12 digital outs ' ' See: http://forums.parallax.com/forums/default.aspx?f=7&m=175498 ' and http://www.vexfan.com/viewtopic.php?t=227 ' ' ------------------------------------------------------------------------- ' Conditional Compilation Symbols ' ------------------------------------------------------------------------- '{$DEFINE Test_Mode_OFF} ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSCHS1, TURBO, STACKX, OPTIONX, BOR42 FREQ 50_000_000 ID "VexAtoD" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- PPM PIN RA.0 INPUT ' PPM in (pull-up w/10k) Controls PIN RBC OUTPUT Control0 PIN RB.0 Control1 PIN RB.1 Control2 PIN RB.2 Control3 PIN RB.3 Control4 PIN RB.4 ' digital control pins Control5 PIN RB.5 Control6 PIN RC.0 Control7 PIN RC.1 Control8 PIN RC.2 Control9 PIN RC.3 Control10 PIN RC.4 Control11 PIN RC.5 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- IsOn CON 1 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- pulseTmr VAR Word ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: Controls = %0000000000000000 Wait_For_Sync: '{$IFDEF Test_Mode} ' since we are waiting here anyways, might as well do the break here WATCH pulseTmr WATCH Controls,16,UBIN BREAK '{$ENDIF} pulseTmr = 0 DO WHILE PPM = 0 PAUSEUS 1 INC pulseTmr LOOP IF pulseTmr < 4000 THEN Wait_For_Sync Main: controls=%0000000000000000 Ctrl_Port0: DO WHILE PPM = 1 ' complete framing pulse LOOP pulseTmr = 0 DO WHILE PPM = 0 ' measure timing pulse PAUSEUS 5 INC pulseTmr LOOP IF pulseTmr < 150 THEN ' short pulse? Control0 = IsOn ELSE IF pulseTmr > 250 THEN ' long pulse? Control6 = IsOn ENDIF ENDIF Ctrl_Port1: DO WHILE PPM = 1 ' complete framing pulse LOOP pulseTmr = 0 DO WHILE PPM = 0 ' measure timing pulse PAUSEUS 5 INC pulseTmr LOOP IF pulseTmr < 150 THEN ' short pulse? Control1 = IsOn ELSE IF pulseTmr > 250 THEN ' long pulse? Control7 = IsOn ENDIF ENDIF Ctrl_Port2: DO WHILE PPM = 1 ' complete framing pulse LOOP pulseTmr = 0 DO WHILE PPM = 0 ' measure timing pulse PAUSEUS 5 INC pulseTmr LOOP IF pulseTmr < 150 THEN ' short pulse? Control2 = IsOn ELSE IF pulseTmr > 250 THEN ' long pulse? Control8 = IsOn ENDIF ENDIF Ctrl_Port3: DO WHILE PPM = 1 ' complete framing pulse LOOP pulseTmr = 0 DO WHILE PPM = 0 ' measure timing pulse PAUSEUS 5 INC pulseTmr LOOP IF pulseTmr < 150 THEN ' short pulse? Control3 = IsOn ELSE IF pulseTmr > 250 THEN ' long pulse? Control9 = IsOn ENDIF ENDIF Ctrl_Port4: DO WHILE PPM = 1 ' complete framing pulse LOOP pulseTmr = 0 DO WHILE PPM = 0 ' measure timing pulse PAUSEUS 5 INC pulseTmr LOOP IF pulseTmr < 150 THEN ' short pulse? Control4 = IsOn ELSE IF pulseTmr > 250 THEN ' long pulse? Control10 = IsOn ENDIF ENDIF Ctrl_Port5: DO WHILE PPM = 1 ' complete framing pulse LOOP pulseTmr = 0 DO WHILE PPM = 0 ' measure timing pulse PAUSEUS 5 INC pulseTmr LOOP IF pulseTmr < 150 THEN ' short pulse? Control5 = IsOn ELSE IF pulseTmr > 250 THEN ' long pulse? Control11 = IsOn ENDIF ENDIF GOTO Wait_For_Sync ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- ' ========================================================================= ' User Data ' =========================================================================