Setup Quadrature Encoder Inputs dsPIC33EP256MU806 example: //——————————————- //—– SETUP QUADRATURE ENCODER INPUTS —– //——————————————- //—– SETUP QEI 1 —– QEI1CONbits.QEIEN = 0; //Module counters are disabled QEI1CONbits.CCM = 0; //Quadrature Encoder mode QEI1CONbits.PIMOD = 0; //Index input event does not affect position counter QEI1CONbits.IMV = 0; //Index input event does not affect position counter […]
Category: XC16-dsPIC
I2C
//—– SETUP I2C 2 —– //Used for: I2C2CONbits.I2CEN = 0; I2C2BRG = 93; //400kHz @ 40MHz Fcy I2C2CONbits.I2CEN = 1;
Timers
Setup Timers #include <timer.h> //—– SETUP TIMER 4/5 —– //Used for: Heartbeat OpenTimer45(T4_ON & T4_GATE_OFF & T4_PS_1_1 & T4_SOURCE_INT, (INSTRUCTION_CLOCK_FREQUENCY / 1000)); //1mS irq, 1:1 prescaller WriteTimer45(0); ConfigIntTimer45(T4_INT_PRIOR_1 & T4_INT_ON); //Interrupt priority level 1 //—– SETUP TIMER 6 —– //Used for: Buzzer PWM //4000Hz = 250uS per complete PWM cycle T6CON = 0x8000; //Timer on, […]
Interrupts
Example Interrupt Functions //Timer 45 Interrupt void __attribute__((interrupt, auto_psv)) _T5Interrupt(void) { _T5IF = 0; //Clear interrupt flag //Timer 6 interrupt void __attribute__((interrupt, auto_psv)) _T6Interrupt(void) { _T6IF = 0; //Clear interrupt flag //Timer 7 interrupt void __attribute__((interrupt, auto_psv)) _T7Interrupt(void) { _T7IF = 0; //Clear interrupt flag
IO
Inputs #define INPUT_1 PORTBbits.RB11 #define INPUT_2 _RB11 Outputs #define OUTPUT_1(state) LATBbits.LATB10 = state #define OUTPUT_2(state) _LATB10 = state #define OUTPUT_3(state) (state ? (_LATB10 = 1) : (_LATB10 = 0)) Peripheral Pin Select dsPIC33EP256MU806 example: //—– SETUP PERIPHERAL PIN SELECT —– RPINR14bits.QEA1R = 66; //QEI1 Phase A on RP66 RPINR14bits.QEB1R = 67; //QEI1 Phase B on […]