XC32 Timers

Using A Timer OpenTimer2((T2_ON | T2_IDLE_CON | T2_GATE_OFF | T2_PS_1_1 | T2_SOURCE_INT), 40); INTClearFlag(INT_T2); while (!INTGetFlag(INT_T2)) ;    

Read More

Non IRQ timer

Using a Timer Without An IRQ //Setup the timer OpenTimer2((T2_ON | T2_IDLE_CON | T2_GATE_OFF | T2_PS_1_1 | T2_32BIT_MODE_OFF | T2_SOURCE_INT), 100); INTClearFlag(INT_T2); //Wait for timer to loop while (!INTGetFlag(INT_T2)) ; INTClearFlag(INT_T2);   Faster Bit Test Of IRQ Flag The INTGetFlag() function is not particuarly fast. ┬áIf you want very tight timing then do a bit […]

Read More

Delays

  mS Delay Function Using Core Timer //#define INSTRUCTION_CLOCK_FREQUENCY 80000000 //****************************** //****************************** //********** DELAY MS ********** //****************************** //****************************** //Uses Core Timer void delay_ms (WORD delay) { unsigned int int_status; while(delay–) { int_status = INTDisableInterrupts(); OpenCoreTimer(INSTRUCTION_CLOCK_FREQUENCY / 2000); INTRestoreInterrupts(int_status); mCTClearIntFlag(); while( !mCTGetIntFlag() ) ; } mCTClearIntFlag(); }  

Read More