PIC32MXには5個の16bitTimerが実装されている。
Timer2/3,4/5はペアで使用して32bitTimerとしても使用可能。
Timerに関しては準備されているライブラリを活用した方が
手っ取り早いので,関数群について記載しておく。
マクロが定義されているtimer.hの内容を読めばそれが間違いない。
以下はtimer.hからの抜粋。
- Timer1
OpenTimer1,ConfigIntTimer1
で制御
<Example>
OpenTimer1(T1_ON|T1_SOURCE_INT|T1_PS_1_256, 1000);
ConfigIntTimer1(T1_INT_ON|T1_INT_PRIOR_2); // 割り込み許可|優先順位
INTEnableSystemMultiVectoredInt(); // 全割り込み許可
void __ISR(_TIMER_1_VECTOR,ipl2) T1Handler(void) {
mT1ClearIntFlag();
return;
}
#define OpenTimer1(config, period)
/******************************************************************************
* Available options for config parameter
*****************************************************************************/
// On/off control – values are mutually exclusive
#define T1_ON /* Timer1 ON */
#define T1_OFF
// Stop-in-idle control – values are mutually exclusive
#define T1_IDLE_STOP /* stop during idle */
#define T1_IDLE_CON /* operate during idle */
// Asynchronous write control – values are mutually exclusive
#define T1_TMWDIS_ON /* Asynchronous Write Disable */
#define T1_TMWDIS_OFF
// Timer gate control – values are mutually exclusive
#define T1_GATE_ON /* Timer Gate accumulation mode ON */
#define T1_GATE_OFF
// Timer prescaler control – values are mutually exclusive
#define T1_PS_1_256 /* Prescaler 1:256 */
#define T1_PS_1_64 /* 1:64 */
#define T1_PS_1_8 /* 1:8 */
#define T1_PS_1_1 /* 1:1 */
// Sync option – values are mutually exclusive
#define T1_SYNC_EXT_ON /* Synch external clk input */
#define T1_SYNC_EXT_OFF
// Source selection – values are mutually exclusive
#define T1_SOURCE_EXT /* External clock source */
#define T1_SOURCE_INT /* Internal clock source */
/***********************************
* End config parameter values
************************************/
#define ConfigIntTimer1(config)
/******************************************************************************
* Available options for config parameter
*****************************************************************************/
// Interrupt on/off – values are mutually exclusive
#define T1_INT_ON
#define T1_INT_OFF
// Interrupt priority – values are mutually exclusive
#define T1_INT_PRIOR_7
#define T1_INT_PRIOR_6
#define T1_INT_PRIOR_5
#define T1_INT_PRIOR_4
#define T1_INT_PRIOR_3
#define T1_INT_PRIOR_2
#define T1_INT_PRIOR_1
#define T1_INT_PRIOR_0
// Interrupt sub-priority – values are mutually exclusive
#define T1_INT_SUB_PRIOR_3
#define T1_INT_SUB_PRIOR_2
#define T1_INT_SUB_PRIOR_1
#define T1_INT_SUB_PRIOR_0
/***********************************
* End config parameter values
************************************/
- Timer2,3,4,5
OpenTimer2,ConfigIntTimer2
<Example>
OpenTimer2(T2_ON | T2_IDLE_ON | T2_PS_1_4, 123);
ConfigIntTimer2(T2_INT_ON | T2_INT_PRIOR_3 | T2_INT_SUB_PRIOR1);
定義はTimer2のもの。Timer3,4,5は2を読みかえればOK。
#define OpenTimer2(config, period)
/******************************************************************************
* Available options for config parameter
*****************************************************************************/
// On/off control – values are mutually exclusive
#define T2_ON /* Timer2 ON */
#define T2_OFF
// Stop-in-idle control – values are mutually exclusive
#define T2_IDLE_STOP /* stop during idle */
#define T2_IDLE_CON /* operate during idle */
// Timer gate control – values are mutually exclusive
#define T2_GATE_ON /* Timer Gate accumulation mode ON */
#define T2_GATE_OFF
// Prescale values – values are mutually exclusive
#define T2_PS_1_256 /* Prescaler 1:256 */
#define T2_PS_1_64 /* 1:64 */
#define T2_PS_1_32 /* 1:32 */
#define T2_PS_1_16 /* 1:16 */
#define T2_PS_1_8 /* 1:8 */
#define T2_PS_1_4 /* 1:4 */
#define T2_PS_1_2 /* 1:2 */
#define T2_PS_1_1 /* 1:1 */
// 32-bit or 16-bit – values are mutually exclusive
#define T2_32BIT_MODE_ON /* Enable 32-bit mode */
#define T2_32BIT_MODE_OFF
// Sync external clock option – values are mutually exclusive
#define T2_SOURCE_EXT /* External clock source */
#define T2_SOURCE_INT /* Internal clock source */
/***********************************
* End config parameter values
************************************/
#define ConfigIntTimer2(config)
/******************************************************************************
* Available options for config parameter
*****************************************************************************/
// Interrupt on/off – values are mutually exclusive
#define T2_INT_ON /* T2 Interrupt Enable */
#define T2_INT_OFF
// Interrupt priority – values are mutually exclusive
#define T2_INT_PRIOR_7
#define T2_INT_PRIOR_6
#define T2_INT_PRIOR_5
#define T2_INT_PRIOR_4
#define T2_INT_PRIOR_3
#define T2_INT_PRIOR_2
#define T2_INT_PRIOR_1
#define T2_INT_PRIOR_0
// Interrupt sub-priority – values are mutually exclusive
#define T2_INT_SUB_PRIOR_3
#define T2_INT_SUB_PRIOR_2
#define T2_INT_SUB_PRIOR_1
#define T2_INT_SUB_PRIOR_0
/***********************************
* End config parameter values
************************************/
- Timer2/3,4/5
OpenTimer23,ConfigIntTimer23
<Example>
OpenTimer23(T23_ON|T23_SOURCE_INT|T23_PS_1_16|T23_32BIT_MODE_ON, 3579545);
#define OpenTimer23(config, period)
/******************************************************************************
* Available options for config parameter
*****************************************************************************/
// On/off control – values are mutually exclusive
#define T23_ON /* Timer2 ON */
#define T23_OFF
// Stop-in-idle control – values are mutually exclusive
#define T23_IDLE_STOP /* stop during idle */
#define T23_IDLE_CON /* operate during idle */
// Timer gate control – values are mutually exclusive
#define T23_GATE_ON /* Timer Gate accumulation mode ON */
#define T23_GATE_OFF
// Prescale values – values are mutually exclusive
#define T23_PS_1_256 /* Prescaler 1:256 */
#define T23_PS_1_64 /* 1:64 */
#define T23_PS_1_32 /* 1:32 */
#define T23_PS_1_16 /* 1:16 */
#define T23_PS_1_8 /* 1:8 */
#define T23_PS_1_4 /* 1:4 */
#define T23_PS_1_2 /* 1:2 */
#define T23_PS_1_1 /* 1:1 */
// 32-bit or 16-bit – values are mutually exclusive
#define T23_32BIT_MODE_ON /* Enable 32-bit mode */
#define T23_32BIT_MODE_OFF
// Sync external clock option – values are mutually exclusive
#define T23_SOURCE_EXT /* External clock source */
#define T23_SOURCE_INT /* Internal clock source */
/***********************************
* End config parameter values
************************************/
#define ConfigIntTimer23(config)
/******************************************************************************
* Available options for config parameter
*****************************************************************************/
// Interrupt on/off – values are mutually exclusive
#define T23_INT_ON /* Interrupt Enable */
#define T23_INT_OFF
// Interrupt priority – values are mutually exclusive
#define T23_INT_PRIOR_7
#define T23_INT_PRIOR_6
#define T23_INT_PRIOR_5
#define T23_INT_PRIOR_4
#define T23_INT_PRIOR_3
#define T23_INT_PRIOR_2
#define T23_INT_PRIOR_1
#define T23_INT_PRIOR_0
// Interrupt sub-priority – values are mutually exclusive
#define T23_INT_SUB_PRIOR_3
#define T23_INT_SUB_PRIOR_2
#define T23_INT_SUB_PRIOR_1
#define T23_INT_SUB_PRIOR_0
/***********************************
* End config parameter values
************************************/
コメント