Esempio n. 1
0
//Interrupt handler to
void __ISR(_TIMER_3_VECTOR, ipl3) _Timer3Handler(void)
{
    //Reset the flag
    mT3ClearIntFlag();


}
Esempio n. 2
0
File: main.c Progetto: ChakChel/Ix
/**
 * @fn      void __ISR( _TIMER_3_VECTOR, IPL2SOFT ) Timer3Handler( void )
 * @brief   Vecteur d'interruption du timer 3
 */
void __ISR( _TIMER_3_VECTOR, IPL2SOFT ) Timer3Handler(void){

    // On baisse le flag
    mT3ClearIntFlag();
    // Début de traitement
    flagTraitement = 1;
}
Esempio n. 3
0
// Interrupt Service Routine for TIMER 3. This is used to switch between the
// buzzing and quiet periods when ON_CYCLES or OFF_CYCLES are reached.
extern "C" void __ISR (_TIMER_3_VECTOR, ipl5) T3_IntHandler (void)
{
  alarm--;
  if (alarm == 0) {
    buzzing = !buzzing;
    if (is_buzzer_on && buzzing) {
      switch(BUZZER_PIN) {
        case 9:
          OpenOC4(OC_ON | OC_TIMER3_SRC | OC_PWM_FAULT_PIN_DISABLE, DUTY_CYCLE, 0);
          break;
        case 10:
          OpenOC5(OC_ON | OC_TIMER3_SRC | OC_PWM_FAULT_PIN_DISABLE, DUTY_CYCLE, 0);
          break;
      }
      alarm = ON_CYCLES;
    } else {
      switch(BUZZER_PIN) {
        case 9:  CloseOC4(); break;
        case 10: CloseOC5(); break;
      }
      alarm = OFF_CYCLES;
      pin_write(BUZZER_PIN, LOW);
    }
  }
  // Clear interrupt flag
  // This will break other interrupts and millis() (read+clear+write race condition?)
  //   IFS0bits.T3IF = 0; // DON'T!! 
  // Instead:
  mT3ClearIntFlag();
}
Esempio n. 4
0
// 20Hz ISR
void initTimer3Interrupt(void)
{
    OpenTimer3(T3_ON | T3_PS_1_256, 15625);
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);
}
Esempio n. 5
0
File: main.c Progetto: NxRLab/gibbot
// timer3 ISR
// Read the encoder, and send over the data desired by printMode
void __ISR( _TIMER_3_VECTOR, ipl1) T3Interrupt( void) {
    timesec++;

    int counterval1;
    int counterval2;

    if(!start) {
//        read_7366(MOT, CNTR, readbuf);
//        counterval1 = (((int)(readbuf[0]))<<8) | ((int)(readbuf[1]));
//
//        read_7366(MAG1, CNTR, readbuf);
//        counterval2 = (((int)(readbuf[0]))<<8) | ((int)(readbuf[1]));

        counterval1 = (int)(atan2(((float)ACC1X-505.0),((float)ACC1Y-530.0))*180.0/3.1416);
        counterval2 = (int)(atan2(((float)ACC2X-505.0),((float)ACC2Y-530.0))*180.0/3.1416);

        sprintf(RS232_Out_Buffer,"%i %i %i %i %i\r\n", counterval1, counterval2, delay1,delay2, delay3);
        WriteString(UART3, RS232_Out_Buffer);
    }

    else {
        counterval1 = GYRO1HI;
        counterval2 = GYRO2HI;

        sprintf(RS232_Out_Buffer,"%i %i\r\n", counterval1, counterval2);
        WriteString(UART3, RS232_Out_Buffer);
    }

    // clear interrupt flag and exit
    mT3ClearIntFlag();
}
Esempio n. 6
0
//=============================================
// Configure the Timer 3 interrupt handler
//=============================================
void __ISR(_TIMER_3_VECTOR, T3_INTERRUPT_PRIORITY) Timer3InterruptHandler(void)
{

  // Increment the number of overflows from this timer. Used primarily by Input Capture
  Timer.Var.nOverflows[2]++;

  mT3ClearIntFlag();
}
Esempio n. 7
0
void __T3_ISR _T3Interrupt(void)
{
    // Clear flag
    #ifdef __PIC32MX__
    mT3ClearIntFlag();
    #else
    IFS0bits.T3IF = 0;
    #endif

	TouchProcessTouch();    
}
Esempio n. 8
0
void __T3_ISR _T3Interrupt(void)
{
    TMR3 = 0;
    // Clear flag
    #ifdef __PIC32MX__
    mT3ClearIntFlag();
    #else
    IFS0bits.T3IF = 0;
    #endif

    TouchDetectPosition();
}
Esempio n. 9
0
void __ISR(_TIMER_3_VECTOR, ipl3) Timer3Handler(void) {
    mT3ClearIntFlag();
    printf("timeout\n");
    //printf("mspeed %d\n",motor_command(500));
    //waitabit(1000);
    //printf("angle %f\n",get_AHRS_angle());
    //waitabit(1000);
   // printf("speed %f\n", get_AHRS_rate());
    //waitabit(500000); //works with 1000000 and 500000
    //printf("mspeed %d\n\n", motor_command(500));
    printf("duty cycle %d\n", PWM_GetDutyCycle(PWM_PORTY04));
    motor_command(300);
    //MDBSS ^= 1;
}
Esempio n. 10
0
File: ask.c Progetto: 10to7/RFIDler
// h/w clock ASK emulator - initialise data pointers for ISR and start timer 2
// args: clock pulsewidth (NOT period!), data as array of 0/1, repeat
void write_ASK_HW_clock(unsigned int pulse, BYTE *data, unsigned int tpb, unsigned int repeat)
{
    // convert to ticks
    pulse= CONVERT_TO_TICKS(pulse);
    // we only need to tick once per bit
    pulse *= (unsigned long) tpb;

    // point globals at data for ISR
    EMU_ThisBit= *data;
    EMU_Data= data + 1;
    EMU_Reset_Data= data;
    EMU_DataBitRate= 1;
    EMU_SubCarrier_T0= 1;

    EMU_Repeat= repeat;

    // if we're manchester or bi-phase encoding, we want to clock twice as fast so we can toggle on half-bit
    if(RFIDlerConfig.Manchester || RFIDlerConfig.BiPhase)
    {
        pulse /= 2;
        EMU_SubCarrier_T0 *= 2;
        EMU_DataBitRate *= 2;
    }

    // make sure no clock is running
    stop_HW_clock();
    
    // set mode
    EmulationMode= MOD_MODE_ASK_OOK;

    // make sure nobody's using our timer
    CloseTimer3();

    // tri-state on, clock low
    READER_CLOCK_ENABLE_ON();
    CLOCK_COIL= LOW;

    // emulator mode
    COIL_MODE_EMULATOR();

    // this is also a semaphore so the rest of the code knows we're running
    mLED_Emulate_On();

    // start timer - ISR will send data
    OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, pulse - 1L);
    mT3SetIntPriority(6);
    mT3ClearIntFlag();
    mT3IntEnable(TRUE);
}
Esempio n. 11
0
/**************************************************************************************************
Timer 3 interrupt.
Used to generate the horiz and vert sync pulse under control of the state machine
***************************************************************************************************/
void __ISR(_TIMER_3_VECTOR, IPL7SOFT) T3Interrupt(void) {
    static int *VPtr;
    static unsigned char AlternateField = 0;                        // used to count odd/even fields in composite video
    static unsigned int LineCnt = 1;

    switch ( VState) {    											// vertical state machine
        case SV_PREEQ:  // 0            							// prepare for the new horizontal line
            VPtr = VideoBuf;
            LineCnt = 1;
            break;

        case SV_SYNC:   // 1
            /*
            if(!vga) {                                              // if the video is composite
                P_VID_OC_REG = SvSyncT;                             // start the vertical sync pulse for composite
            	VCount += AlternateField;                           // in composite video the alternative field has one extra line
            	AlternateField ^= 1;
            }
            */
            P_VERT_SET_LO;										    // start the vertical sync pulse for vga
            break;

        case SV_POSTEQ: // 2
        	//if(!vga) P_VID_OC_REG = C_HSYNC_T; 			            // end of the vertical sync pulse for composite
            P_VERT_SET_HI;                                          // end of the vertical sync pulse for vga
            break;

        case SV_LINE:   // 3
            P_SPI_INPUT = 0;                                        // preload the SPI with 4 zero bytes to pad the start of the video
            //if(vga)
                DCH1SSA = KVA_TO_PA((void*) (VPtr));                // update the DMA1 source address (DMA1 is used for VGA data)
            //else
             //   DCH0SSA = KVA_TO_PA((void*) (VPtr - 1));            // update the DMA0 source address (DMA0 is used for composite data)
            if(!Display24Lines || LineCnt++ % 3) VPtr += HBuf/32;   // move the pointer to the start of the next line
            DmaChnEnable(1);                                        // arm the DMA transfer
            break;
   }

    if (--VCount == 0) {											// count down the number of lines
        VCount = VC[VState&3];										// set the new count
        VState = VS[VState&3];    									// and advance the state machine
    }

    mT3ClearIntFlag();    											// clear the interrupt flag
}
Esempio n. 12
0
void initPIC() {
    SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);

    initLEDs();
    initSerialNU32v2();

    // Setup and turn off electromagnets
    EMAG1 = 0;
    EMAG2 = 0;
    TRISEbits.TRISE7 = 0;
    TRISCbits.TRISC1 = 0;

    // Direction Output
    DIR = 1;
    TRISAbits.TRISA9 = 0;

    setup_counters();

    CloseADC10();
#define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
#define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_16 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
#define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
#define PARAM4  ENABLE_AN0_ANA | ENABLE_AN1_ANA | ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN5_ANA | ENABLE_AN15_ANA
    OpenADC10(PARAM1, PARAM2, PARAM3, PARAM4, 0);
    EnableADC10();

    // 20kHz PWM signal, duty from 0-1000, pin D3
    OpenTimer2(T2_ON | T2_PS_1_4, MAX_DUTY);
    OpenOC4(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
    SetDCOC4PWM(0);

    // 200 Hz ISR
    OpenTimer3(T3_ON | T3_PS_1_256, (6250/4 - 1));
    //OpenTimer3(T3_ON | T3_PS_1_256, (62500 - 1));
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);

    INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
    INTEnableSystemMultiVectoredInt();
}
Esempio n. 13
0
// h/w clock PSK emulator - initialise data pointers for ISR and start timer 2
// args: clock period, data as array of 0/1, fc per bit, sub-carrier ticks, repeat
void write_PSK1_HW_clock(unsigned int period, BYTE *data, unsigned int fcpb, unsigned int c0, unsigned int repeat)
{
    // convert to ticks
    period= CONVERT_TO_TICKS(period);
    // for psk we want a full clock cycle, not a tick
    period *= 2;

    // point globals at data for ISR
    EMU_ThisBit= *data;
    EMU_Data= data + 1;
    EMU_Reset_Data= data;
    EMU_DataBitRate= fcpb;
    EMU_SubCarrier_T0= c0;
    EMU_Repeat= repeat;

    // set mode
    EmulationMode= MOD_MODE_PSK1;

    // make sure no clock is running
    stop_HW_clock();

    // make sure nobody's using our timers
    CloseTimer3();

    // tri-state on, clock low
    READER_CLOCK_ENABLE_ON();
    CLOCK_COIL= LOW;

    // emulator mode
    COIL_MODE_EMULATOR();

    // this is also a semaphore so the rest of the code knows we're running
    mLED_Emulate_On();

    // start timer - ISR will send data
    OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, period / 2L - 1L);
    mT3SetIntPriority(6);
    mT3ClearIntFlag();
    mT3IntEnable(TRUE);
}
Esempio n. 14
0
File: fsk.c Progetto: 10to7/RFIDler
// h/w clock FSK emulator - initialise data pointers for ISR and start timer 2
// args: clock pulsewidth (NOT period!), data as array of 0/1, T0 sub-carrier ticks, T1 sub-carrier ticks, repeat
void write_FSK_HW_clock(unsigned long pulse, BYTE *data, unsigned int tpb, unsigned int t0, unsigned int t1, unsigned int repeat)
{
    // convert to ticks
    pulse= CONVERT_TO_TICKS(pulse);

    // point globals at data for ISR
    EMU_ThisBit= *data;
    EMU_Data= data + 1;
    EMU_Reset_Data= data;
    EMU_Repeat= repeat;
    EMU_DataBitRate= tpb;
    EMU_SubCarrier_T0= t0;
    EMU_SubCarrier_T1= t1;

    // set mode
    EmulationMode= MOD_MODE_FSK;

    // make sure no clock is running
    stop_HW_clock();

    // make sure nobody's using our timer
    CloseTimer3();

    // emulator mode
    COIL_MODE_EMULATOR();

    // tri-state on, clock low
    READER_CLOCK_ENABLE_ON();
    CLOCK_COIL= LOW;

    // this is also a semaphore so the rest of the code knows we're running
    mLED_Emulate_On();

    // start timer - ISR will send data
    OpenTimer3( T3_ON | T3_PS_1_1 | T3_SOURCE_INT, pulse - 1L);
    mT3SetIntPriority(6);
    mT3ClearIntFlag();
    mT3IntEnable(TRUE);
}
void __ISR(_TIMER_3_VECTOR, ipl2) _InterruptHandler_TMR3(void)
{

    // if(current_block->direction_bits[Y_AXIS])
    //   PORTSetBits(xAxis.directionPin.port, xAxis.directionPin.pin);
    // else
    //     PORTClearBits(yAxis.directionPin.port, yAxis.directionPin.pin);
    if(steps_X)
    {
        if(!(mPORTGReadBits(xAxis.enablePin.pin)))
            steps_X--;
    }
    else if (current_block != Null)
    {
        if(current_block->steps_x)
        {
            if(!(mPORTGReadBits(xAxis.enablePin.pin)))
                current_block->steps_x--;
        }
        else
        {
            //CloseOC2();
            BSP_AxisDisable(X_AXIS);
            BSP_Timer3Stop();
        }
    }
    else
    {
        //CloseOC2();
        BSP_AxisDisable(X_AXIS);
        BSP_Timer3Stop();
    }
     
    // clear the interrupt flag
    mT3ClearIntFlag();
}
void __T3_ISR _T3Interrupt(void)
{
static SHORT tempX, tempY;
SHORT temp;

    switch(state){

        case SET_VALUES:
            if(!AD1CON1bits.DONE)
                break;

            if( (WORD)PRESS_THRESHOULD < (WORD)ADC1BUF0 ){
                adcX = -1; adcY = -1;
            }else{
                adcX = tempX; adcY = tempY;
            }
            state = RUN_POT;

        case RUN_POT:
            AD1CHS = ADC_POT;      // switch ADC channel
            AD1CON1bits.SAMP = 1;  // run conversion
            state = GET_POT;
            break;
        
        case GET_POT:
            if(!AD1CON1bits.DONE)
                break;

            adcPot = ADC1BUF0;
            state  = SET_X;

        case SET_X:
            AD1CHS = ADC_XPOS;     // switch ADC channel

            ADPCFG_XPOS = 0;       // analog
            ADPCFG_YPOS = 1;       // digital

            TRIS_XPOS = 1;
            TRIS_YPOS = 1;
            TRIS_XNEG = 1;
            LAT_YNEG = 0;
            TRIS_YNEG = 0;

            AD1CON1bits.SAMP = 1;  // run conversion
            state = CHECK_X;
            break;

        case CHECK_X:
            if(!AD1CON1bits.DONE)
                break;

            if( (WORD)PRESS_THRESHOULD > (WORD)ADC1BUF0 ){
                LAT_YPOS  = 1;
                TRIS_YPOS = 0;
                tempX = -1;
                state = RUN_X;
            }else{
                adcX = -1; adcY = -1;
                state = RUN_POT;
                break;
            }

        case RUN_X:
            AD1CON1bits.SAMP = 1;
            state = GET_X;
            break;

        case GET_X:
            if(!AD1CON1bits.DONE)
                break;

            temp = ADC1BUF0;
            if(temp != tempX){
                tempX = temp;
                state = RUN_X;
                break;                                
            }
            TRIS_YPOS = 1;
            AD1CON1bits.SAMP = 1;
            state = SET_Y;
            break;

        case SET_Y:
            if(!AD1CON1bits.DONE)
                break;

            if( (WORD)PRESS_THRESHOULD < (WORD)ADC1BUF0 ){
                adcX = -1; adcY = -1;
                state = RUN_POT;
                break;
            }

            AD1CHS = ADC_YPOS;     // switch ADC channel

            ADPCFG_XPOS = 1;       // digital
            ADPCFG_YPOS = 0;       // analog

            TRIS_XPOS = 1;
            TRIS_YPOS = 1;
            LAT_XNEG = 0;
            TRIS_XNEG = 0;
            TRIS_YNEG = 1;

            AD1CON1bits.SAMP = 1;  // run conversion
            state = CHECK_Y;
            break;

        case CHECK_Y:
            if(!AD1CON1bits.DONE)
                break;

            if( (WORD)PRESS_THRESHOULD > (WORD)ADC1BUF0 ){
                LAT_XPOS  = 1;
                TRIS_XPOS = 0;
                tempY = -1;
                state = RUN_Y;
            }else{
                adcX = -1; adcY = -1;
                state = RUN_POT;
                break;
            }

        case RUN_Y:
            AD1CON1bits.SAMP = 1;
            state = GET_Y;
            break;

        case GET_Y:
            // Get Y value
            if(!AD1CON1bits.DONE)
                break;

            temp = ADC1BUF0;
            if(temp != tempY){
                tempY = temp;
                state = RUN_Y;
                break;                                
            }
            TRIS_XPOS = 1;
            AD1CON1bits.SAMP = 1;
            state = SET_VALUES;
            break;

        default:
            state = SET_X;
    }
    // Clear flag
#ifdef __PIC32MX__
    mT3ClearIntFlag();
#else
    IFS0bits.T3IF = 0;
#endif

}
Esempio n. 17
0
int main(void) {
	timesec=0;
	// set PIC32 to max computing power
	SYSTEMConfig(SYS_FREQ, SYS_CFG_ALL);
	INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
	INTEnableSystemMultiVectoredInt();   
    initLEDs(); 	
    LED0 = 1;
    LED1 = 1;
    initSerialNU32v2();
	setup_counters();

  	CloseADC10();
  	#define PARAM1  ADC_MODULE_ON | ADC_FORMAT_INTG | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_ON
  	#define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_ON | ADC_SAMPLES_PER_INT_16 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
  	#define PARAM3  ADC_CONV_CLK_INTERNAL_RC | ADC_SAMPLE_TIME_31
  	#define PARAM4  ENABLE_AN0_ANA | ENABLE_AN1_ANA | ENABLE_AN2_ANA | ENABLE_AN3_ANA | ENABLE_AN5_ANA | ENABLE_AN15_ANA
  	OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4,0);
  	EnableADC10();


    // Setup and turn off electromagnets
    EMAG1 = 0; EMAG2 = 0; 
    TRISEbits.TRISE7 = 0; TRISCbits.TRISC1 = 0;
	//Direction Output
	DIR = 1;
  	TRISAbits.TRISA9 = 0;
	//g-select Outputs
	GSEL1 = 0; GSEL2 = 0;
  	TRISEbits.TRISE2 = 0; TRISCbits.TRISC13= 0;
  	//0g Inputs
  	TRISAbits.TRISA0 = 1;
  	TRISAbits.TRISA4 = 1;

  	// 20kHz PWM signal, duty from 0-1000, pin D3
  	OpenTimer2(T2_ON | T2_PS_1_4, 1000);
  	OpenOC4(OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
  	HBridgeDuty = 0;
  	SetDCOC4PWM(HBridgeDuty);

    // 20Hz ISR
    OpenTimer3(T3_ON | T3_PS_1_256, 15625);
    mT3SetIntPriority(1);
    mT3ClearIntFlag();
    mT3IntEnable(1);


	while(1) {
		if(start){
			EMAG2=0;
			SetDCOC4PWM(100);
			delaysec(delay1);
			SetDCOC4PWM(1000);		
			delaysec(delay2);
			SetDCOC4PWM(500);
			delaysec(delay3);
			EMAG2=1;
			SetDCOC4PWM(0);	

//			EMAG1=0;
//			SetDCOC4PWM(900);
//			DIR = 0;
//			delaysec(delay1);
//			SetDCOC4PWM(0);
//			delaysec(delay2);
//			SetDCOC4PWM(700);
//			delaysec(delay1);
//			SetDCOC4PWM(1000);
//			EMAG1=1;

			start=0;
		}
	}
}
Esempio n. 18
0
// Emulate TAG ISR
// this ISR does the actual send of a '*' terminated bitstream
// mLED_Antenna is set during emulation, and can be used as a semaphore to detect emulation in progress
// note that the best resolution we can achieve on a pic32 seems to be 2us
//
// setup routine is responsible for:
//
//   setting clock period and arming interrupt
//   setting global variables:
//
//     EMU_ThisBit              - the next bit to output (as 0x00 or 0x01)
//     *EMU_Data                - pointer to array of 0x00/0x01 values, '*' terminated
//                                inital value should be &EMU_ThisBit + 1
//     *EMU_Reset_Data          - pointer to the complete data array
//     EMU_Repeat               - number of times to repeat full data pattern (0 means send once)
//     EMU_Invert               - Invert 0x00/0x01 values TRUE/FALSE
//     EMU_DataBitRate          - Frame Clocks Per Bit
//     EMU_SubCarrier_T0         - 1st sub-carrier Frame Clocks
//     EMU_SubCarrier_T1        - 2nd sub-carrier Frame Clocks
//     EMU_Manchester           - Manchester Encoding TRUE/FALSE
//     EMU_BiPhase              - BiPhase Encoding TRUE/FALSE
void __ISR(_TIMER_3_VECTOR, ipl7auto) emulation_send_bit (void)
{
    static unsigned int count= 0;

    // ack interrupt
    mT3ClearIntFlag();

#ifdef RFIDLER_DEBUG
    // show bit value
    //DEBUG_PIN_1= EMU_ThisBit;

    // show tick
    //DEBUG_PIN_2= !DEBUG_PIN_2;
#endif

    // are we finished?
    if(EMU_ThisBit == '*')
    {
        if(!EMU_Background && !(EMU_Repeat--))
        {
            CloseTimer3();
            mLED_Emulate_Off();
            count= 0;
            COIL_OUT= 0;
            return;
        }
        // repeat
        EMU_Data= EMU_Reset_Data;
        EMU_ThisBit= *(EMU_Data++);
        count= 0;
    }

    // count reflects the FC we are about to process, starting from 1
    // so we can calulate bit periods and sub-carriers.
    // count should be reset after each full bit.
    ++count;

    // output and set up bit for next tick
    switch(EmulationMode)
    {
        // ASK / OOK - we get called once per bit just toggle the line according to bit value
        //
        // MANCHESTER/BI_PHASE - we get called twice per bit, half-bit toggles
        //
        case MOD_MODE_ASK_OOK:
            // output half-bit? manchester always toggles, biphase only toggles if it's a 1
            if(count == EMU_SubCarrier_T0 && (RFIDlerConfig.Manchester || (RFIDlerConfig.BiPhase && (EMU_ThisBit ^ RFIDlerConfig.Invert))))
                COIL_OUT= !COIL_OUT;
            // output current bit
            else
            {
                // biphase always toggles on a full bit period
                if(RFIDlerConfig.BiPhase)
                {
                    if (count % EMU_DataBitRate)
                    COIL_OUT= !COIL_OUT;
                }
                else
                    COIL_OUT= (EMU_ThisBit ^ RFIDlerConfig.Invert);
            }
            // is this a bit period?
            if (count == EMU_DataBitRate)
            {
                // set the next bit value
                EMU_ThisBit= *(EMU_Data++);
                count= 0;
            }
            break;

        // FSK - we get called N times per bit
        // create sub-carriers T0 & T1 for bit values 0 and 1
        // e.g. if bit period N is 40 ticks (RF/40) and T0 is RF/8 and T1 is RF/5
        // then T0 is 8 ticks and T1 is 5 ticks.
        // note that we must independantly check for end of bit period for each sub-carrier
        // to cater for cases where there is no common clock multiple (e.g. HID: RF/8 & RF/10)
        case MOD_MODE_FSK1:
        case MOD_MODE_FSK2:
            // output sub-carriers
            // if current bit is a '1'
            if(EMU_ThisBit ^ RFIDlerConfig.Invert)
            {
                if(!(count % EMU_SubCarrier_T1))
                    COIL_OUT= !COIL_OUT;
                // rounded bit period?
                if (!(count % ((EMU_DataBitRate / EMU_SubCarrier_T1) * EMU_SubCarrier_T1)))
                {
                    // set the next bit value
                    EMU_ThisBit= *(EMU_Data++);
                    count= 0;
                }
            }
            // if current bit is a '0'
            else
            {
                if(!(count % EMU_SubCarrier_T0))
                    COIL_OUT= !COIL_OUT;
                // rounded bit period?
                if (!(count % ((EMU_DataBitRate / EMU_SubCarrier_T0) * EMU_SubCarrier_T0)))
                {
                    // set the next bit value
                    EMU_ThisBit= *(EMU_Data++);
                    count= 0;
                }
            }
            break;

        // TODO: PSK2, PSK3
        // PSK1 - we get called N times per bit
        // create sub-carrier
        // half-bit phase shift if bit changes
        case MOD_MODE_PSK1:
            // output sub-carrier?
            if(!(count % EMU_SubCarrier_T0))
                COIL_OUT= !COIL_OUT;
            // output current bit
            else
                COIL_OUT= (EMU_ThisBit ^ RFIDlerConfig.Invert);
            // is this is a bit period?
            if (count == EMU_DataBitRate)
            {
                // set the next bit value
                EMU_ThisBit= *(EMU_Data++);
                count= 0;
            }
            break;

        default:
            break;
    }
//#ifdef RFIDLER_DEBUG
//    // show modulator
//    DEBUG_PIN_3= COIL_OUT;
//#endif
}
Esempio n. 19
0
/****************************************************************************
 Function: Timer5IntHandler

 Parameters: None.

 Returns: None.

 Description
    Implements the Stepper motor FULL STEP drive state machine.

 Notes
    

 Author: Gabriel Hugh Elkaim, 2011.12.15 16:42
 ****************************************************************************/
void __ISR(_TIMER_3_VECTOR, ipl4) Timer3IntHandler(void)
{
    static unsigned short timerLoopCount = 0;
    LED_BANK1_0 ^= 1;
    if (++timerLoopCount > overflowReps) {
        timerLoopCount = 0;
        LED_BANK1_1 ^= 1;
        // execute Stepper Drive state machine here
        switch(stepperState) {
            case off: // should not get here
                dbprintf("\noff");
                T5CONbits.ON = 0; // halt timer5
                ShutDownDrive();
                CloseTimer5();
                break;

            case inited:
            case halted:
            case waiting:
                ShutDownDrive();
                if (stepCount < 0) stepCount = 0;
                LED_BANK1_2 ^= 1;
                break;
            //------------------- Full-Step --------------------------
            case stepping:
                switch(stepperMode) {
                case full:
                    if (--stepCount <= 0) stepperState = waiting;
                    LED_BANK1_3 ^= 1;
                    TurnOnDrive(); // enable both coils
                    switch(coilState) {
                        case step_one:
                            // coil drive both forward
                            ADirectionOn();
                            BDirectionOn();
                            if (stepDir == FORWARD) coilState = step_two;
                            else coilState = step_four;
                            break;

                        case step_two:
                            // coil drive A forward, B reverse
                            ADirectionOn();
                            BDirectionOff();
                            if (stepDir == FORWARD) coilState = step_three;
                            else coilState = step_one;
                            break;

                        case step_three:
                            // coil drive both reverse
                            ADirectionOff();
                            BDirectionOff();
                            if (stepDir == FORWARD) coilState = step_four;
                            else coilState = step_two;
                            break;

                        case step_four:
                            // coild drive A reverse, B forward
                            ADirectionOff();
                            BDirectionOn();
                            if (stepDir == FORWARD) coilState = step_one;
                            else coilState = step_three;
                            break;

                    } // end of full-step drive
                    break;
                //------------------- Wave Drive ------------------------
                case wave:
                    if (--stepCount <= 0) stepperState = waiting;
                    LED_BANK1_3 ^= 1;
                    switch(coilState) {
                        case step_one:
                            // coil drive both forward
                            AEnable();
                            BDisable();
                            ADirectionOn();
                            if (stepDir == FORWARD) coilState = step_two;
                            else coilState = step_four;
                            printf("\nStep one, wave");
                            break;

                        case step_two:
                            // coil drive A forward, B reverse
                            ADisable();
                            BEnable();
                            BDirectionOff();
                            if (stepDir == FORWARD) coilState = step_three;
                            else coilState = step_one;
                            printf("\nStep two, wave");
                            break;

                        case step_three:
                            // coil drive both reverse
                            AEnable();
                            BDisable();
                            ADirectionOff();
                            if (stepDir == FORWARD) coilState = step_four;
                            else coilState = step_two;
                            printf("\nStep three, wave");
                            break;

                        case step_four:
                            // coild drive A reverse, B forward
                            ADisable();
                            BEnable();
                            BDirectionOn();
                            if (stepDir == FORWARD) coilState = step_one;
                            else coilState = step_three;
                            printf("\nStep four, wave");
                            break;

                    } // end of wave drive
                    break;
                //------------------- Half Step --------------------------
                case half:
                    if (--stepCount <= 0) stepperState = waiting;
                    LED_BANK1_3 ^= 1;
                    switch(coilState) {
                        case step_one:
                            // coil drive both forward
                            AEnable();
                            BEnable();
                            ADirectionOn();
                            BDirectionOn();
                            if (stepDir == FORWARD) coilState = step_two;
                            else coilState = step_eight;
                            break;

                        case step_two:
                            // coil drive A forward, B reverse
                            AEnable();
                            BDisable();
                            ADirectionOn();
                            BDirectionOff();
                            if (stepDir == FORWARD) coilState = step_three;
                            else coilState = step_one;
                            break;

                        case step_three:
                            // coil drive both reverse
                            AEnable();
                            BEnable();
                            ADirectionOn();
                            if (stepDir == FORWARD) coilState = step_four;
                            else coilState = step_two;
                            break;

                        case step_four:
                            // coild drive A reverse, B forward
                            ADisable();
                            BEnable();
                            BDirectionOff();
                            if (stepDir == FORWARD) coilState = step_five;
                            else coilState = step_three;
                            break;
                        case step_five:
                            // coil drive both forward
                            AEnable();
                            BEnable();
                            ADirectionOff();  // ?
                            BDirectionOff();
                            if (stepDir == FORWARD) coilState = step_six;
                            else coilState = step_four;
                            break;

                        case step_six:
                            // coil drive A forward, B reverse
                            AEnable();
                            BDisable();
                            ADirectionOff();
                            if (stepDir == FORWARD) coilState = step_seven;
                            else coilState = step_five;
                            break;

                        case step_seven:
                            // coil drive both reverse
                            AEnable();
                            BEnable();
                            ADirectionOff();
                            BDirectionOn();
                            if (stepDir == FORWARD) coilState = step_eight;
                            else coilState = step_six;
                            break;

                        case step_eight:
                            // coild drive A reverse, B forward
                            ADisable();
                            BEnable();
                            BDirectionOn();
                            if (stepDir == FORWARD) coilState = step_one;
                            else coilState = step_seven;
                            break;

                    } // end of half-step drive
                    break;
                } // end of switch(stepperMode)
        } // end of switch(stepperState)
    }
    mT3ClearIntFlag();
}
Esempio n. 20
0
/****************************************************************************
 Function: Timer5IntHandler

 Parameters: None.

 Returns: None.

 Description
    Implements the Stepper motor FULL STEP drive state machine.

 Notes
    

 Author: Gabriel Hugh Elkaim, 2011.12.15 16:42
 ****************************************************************************/
void __ISR(_TIMER_3_VECTOR, ipl4) Timer3IntHandler(void)
{
    static unsigned short timerLoopCount = 0;
    LED_BANK1_0 ^= 1;
    if (++timerLoopCount > overflowReps) {
        timerLoopCount = 0;
        LED_BANK1_1 ^= 1;
        // execute Stepper Drive state machine here
        switch(stepperState) {
            case off: // should not get here
                dbprintf("\noff");
                T5CONbits.ON = 0; // halt timer5
                ShutDownDrive();
                CloseTimer5();
                break;

            case inited:
            case halted:
            case waiting:
                ShutDownDrive();
                if (stepCount < 0) stepCount = 0;
                LED_BANK1_2 ^= 1;
                break;

            case stepping:
                if (--stepCount <= 0) stepperState = waiting;
                LED_BANK1_3 ^= 1;
                TurnOnDrive();
                switch(coilState) {
                    case step_one:
                        // coil drive both forward
                        COIL_A_DIRECTION = 1;
                        COIL_B_DIRECTION = 1;
                        if (stepDir == FORWARD) coilState = step_two;
                        else coilState = step_four;
                        break;

                    case step_two:
                        // coil drive A forward, B reverse
                        COIL_A_DIRECTION = 1;
                        COIL_B_DIRECTION = 0;
                        if (stepDir == FORWARD) coilState = step_three;
                        else coilState = step_one;
                        break;

                    case step_three:
                        // coil drive both reverse
                        COIL_A_DIRECTION = 0;
                        COIL_B_DIRECTION = 0;
                        if (stepDir == FORWARD) coilState = step_four;
                        else coilState = step_two;
                        break;

                    case step_four:
                        // coild drive A reverse, B forward
                        COIL_A_DIRECTION = 0;
                        COIL_B_DIRECTION = 1;
                        if (stepDir == FORWARD) coilState = step_one;
                        else coilState = step_three;
                        break;
                }
                break;
        }
    }
    mT3ClearIntFlag();
}