;******************************************************** ; FICHIER........: Mixer.ASM ; AUTEUR ........: S. Lichtenberger ; DESCRIPTION ...: Module mixer ; ; NOTES .........: ; COPYRIGHT .....: S. Lichtenberger ; Version .......: 27/05/2009 ;******************************************************** PROCESSOR PIC12F675 INCLUDE __config _MCLRE_OFF & _CP_OFF & _INTRC_OSC_NOCLKOUT & _WDT_OFF ; Définition GPIO et TRIS ; OutA EQU 0 ; Aileron 1, broche 7 OutB EQU 1 ; Aileron 2, broche 6 InA EQU 4 ; Voie A du récepteur, broche 3 InB EQU 5 ; Voie B du récepteur, broche 2 BitInA EQU B'00010000' ; 2^InA BitInB EQU B'00100000' ; 2^InB TrisBits EQU B'11111100' ; GP0 et GP1 en sorties, le reste en entrées OptionBits EQU B'00000000' ; Pull up ON #DEFINE Page0 Bcf STATUS,5 #DEFINE Page1 Bsf STATUS,5 CBLOCK 0x20 ; Mémoires RAM PremierPulse : 1 ; 4 ou 5 selon le 1er pulse trouvé SecondPulse :1 ; Masque pour mesure du second pulse ValeurPulse1 : 1 ; Temps pulse IN ValeurPulse2 : 1 ValeurPulseOut1 : 1 ; Temps pulse Out ValeurPulseOut2 : 1 InterPulse : 1 ; Compteur entre pulses A et B ValeurNeutre : 1 ; Valeur du neutre Cmpt1 :1 ; Compteur de délai ENDC ; ========================================================================= ; Départ Coldstart: ORG 0 page1 call 0x3fe movwf OSCCAL ; Init Oscal pour 4 MHz movlw OptionBits movwf OPTION_REG movlw Trisbits movwf TRISIO movlw 0 movwf ANSEL page0 movlw b'00000111' ; Comparateurs OFF movwf CMCON movlw b'0000000' movwf ADCON0 ; convertisseur OFF clrf GPIO ; Prog Sortie à 0 ; Fin des initialisations Main: clrf InterPulse AttSynchro: incfsz InterPulse goto AttS goto AttFront ; Synchro trouvée AttS: bsf GPIO,OutA movlw 6 ; Au moins 6,5 ms de synchro movwf Cmpt1 Bcl2: decfsz Cmpt1 goto Bcl2 movfw GPIO andlw BitInA + BitInB btfss STATUS,Z clrf InterPulse goto AttSynchro ; Attente InA et InB à 0 pendant 6 ms AttFront: ; Attente d'un pulse (A ou B) movfw GPIO andlw BitInA + BitInB btfsc STATUS,Z goto AttFront ; Attente un front movwf PremierPulse ; Contient le N° de la première entrée trouvée movwf SecondPulse movlw BitInA + BitInB xorwf SecondPulse,F ; car on lira d'abord la seconde entrée ; Lecture du neutre clrf ValeurNeutre AttA0: movfw GPIO btfsc GPIO,InA goto AttA0 ; Attente InA à 0 AttA1: movfw GPIO btfss GPIO,InA goto AttA1 ; Attente InA à 1 AttA00: incf ValeurNeutre nop nop nop nop nop nop movfw GPIO btfsc GPIO,InA goto AttA00 ; Attente InA à 0 AttSynchro1: movfw GPIO andlw BitInA + BitInB btfss STATUS,Z goto AttSynchro1 ; Attente InA et InB à 0 BclMain: clrf ValeurPulse1 clrf ValeurPulse2 ; Attendre la montée du premier pulse, repéré par un bit dans PremierPulse AttPremier: movfw GPIO andwf PremierPulse,W btfsc STATUS,Z goto AttPremier AttFinPremier: ; le mesurer incf ValeurPulse1 nop nop nop nop movfw GPIO andwf PremierPulse,W btfss STATUS,Z goto AttFinPremier AttSecond: ; Attendre le second pulse movfw GPIO andwf SecondPulse,W btfsc STATUS,Z goto AttSecond AttFinSecond: ; le mesurer incf ValeurPulse2 nop nop nop nop movfw GPIO andwf SecondPulse,W btfss STATUS,Z goto AttFinSecond ; Faire le calcul ; OutA = InA/2 + InB/2 ; OutB = Neutre - InB/2 + InA/2 bcf STATUS,C rrf ValeurPulse1 ; On divise les pulses pae 2 bcf STATUS,C rrf ValeurPulse2 movfw ValeurPulse1 addwf ValeurPulse2,W movwf ValeurPulseOut1 movfw ValeurNeutre ; Maxi 128 addwf ValeurPulse1,W ; Maxi 128 doc somme < 256 subwf ValeurPulse2,W movwf ValeurPulseOut2 ; On sort les pulses pour pilotage des servos bsf GPIO,OutA BclPulseOut1: nop nop nop nop nop nop nop decfsz ValeurPulseOut1 goto BclPulseOut1 bcf GPIO,OutA bsf GPIO,OutB BclPulseOut2: nop nop nop nop nop nop nop decfsz ValeurPulseOut2 goto BclPulseOut2 bcf GPIO,OutB goto BclMain ;================================================ DE "S. Lichtenberger - Mixer - Version 27/05/2009 R1" ;================================================ ORG 0x3ff retlw 0x28 ; Valeur OSCAL - A lire pour chaque Proc avant son effacement. END