|
SCT (State-Configurable Timers)状态可配定时计数器,SCT可用于各种定时、计数、输出调制和输入捕获操作。如计数器、函数发生器、PWM电机控制(最多四路)、红外遥控编码、解码、PWM解码、PPM调制等。
四个输出建立于某个输入的变换,每个输出可以被用做SCT的可中断输入或者其他需要多个SCT输入来触发SCT响应的应用
四个寄存器指示那个特定的输入源引起了对SCT的中断输入
4个外置的输出可以在特定的时间被采样,并且锁存其他在被SCT输入抢占之前
9个可中断输入。每个SCT的专用可中断输入可以由任意的可中断输入组合来触发
SCT作为一个多通道的标准PWM配置和使用步骤
1、初始化SCT,该函数在sct_pwm.c库文件中
- /* Setup board specific pin muxing */
- static void app_setup_pin(void)
- {
- /* Enable SWM clock before altering SWM */
- Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
- #if defined(BOARD_NXP_LPCXPRESSO_1549)
- /* Connect SCT output 1 to PIO0_29 */
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT1_O, 29);
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT0_O, 3);
- #endif
- Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
- }
复制代码 2、设置SCT频率,该函数在sct_pwm_15xx.c库文件中
- void Chip_SCTPWM_SetRate(LPC_SCT_T *pSCT, uint32_t freq)
- {
- uint32_t rate;
- rate = Chip_Clock_GetSystemClockRate() / freq;;
- /* Stop the SCT before configuration */
- Chip_SCTPWM_Stop(pSCT);
- /* Set MATCH0 for max limit */
- pSCT->REGMODE = 0;
- Chip_SCT_SetMatchCount(pSCT, SCT_MATCH_0, 0);
- Chip_SCT_SetMatchReload(pSCT, SCT_MATCH_0, rate);
- pSCT->EVENT[0].CTRL = 1 << 12;
- pSCT->EVENT[0].STATE = 1;
- /* Set SCT Counter to count 32-bits and reset to 0 after reaching MATCH0 */
- Chip_SCT_Config(pSCT, SCT_CONFIG_32BIT_COUNTER | SCT_CONFIG_AUTOLIMIT_L);
- }
复制代码 3、配置管脚
- /* Setup board specific pin muxing */
- static void app_setup_pin(void)
- {
- /* Enable SWM clock before altering SWM */
- Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
- #if defined(BOARD_NXP_LPCXPRESSO_1549)
- /* Connect SCT output 1 to PIO0_29 */
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT1_O, 29);
- Chip_SWM_MovablePinAssign(SWM_SCT0_OUT0_O, 3);
- #endif
- Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);
- }
复制代码
4、指定一个PWM输出给一个通道,该函数在sct_pwm_15xx.c库文件中
- /* Setup the OUTPUT pin corresponding to the PWM index */
- void Chip_SCTPWM_SetOutPin(LPC_SCT_T *pSCT, uint8_t index, uint8_t pin)
- {
- int ix = (int) index;
- pSCT->EVENT[ix].CTRL = index | (1 << 12);
- pSCT->EVENT[ix].STATE = 1;
- pSCT->OUT[pin].SET = 1;
- pSCT->OUT[pin].CLR = 1 << ix;
- /* Clear the output in-case of conflict */
- pSCT->RES = (pSCT->RES & ~(3 << (pin << 1))) | (0x01 << (pin << 1));
- /* Set and Clear do not depend on direction */
- pSCT->OUTPUTDIRCTRL = (pSCT->OUTPUTDIRCTRL & ~(3 << (pin << 1)));
- }
复制代码 5、设置该通道PWM输出的占空比,该函数在sct_pwm_15xx.h- /**
- * @brief Get number of ticks on per PWM cycle
- * @param pSCT : The base of SCT peripheral on the chip
- * @param index : Index of the PWM 1 to N (see notes)
- * @param ticks : Number of ticks the output should say ON
- * @return None
- * @note @a index will be 1 to N where N is the "Number of
- * match registers available in the SCT - 1" or
- * "Number of OUTPUT pins available in the SCT" whichever
- * is minimum. The new duty cycle will be effective only
- * after completion of current PWM cycle.
- */
- STATIC INLINE void Chip_SCTPWM_SetDutyCycle(LPC_SCT_T *pSCT, uint8_t index, uint32_t ticks)
- {
- Chip_SCT_SetMatchReload(pSCT, (CHIP_SCT_MATCH_REG_T)index, ticks);
- }
复制代码 6、重复步骤3、4、5设置需要的pwm通道(可选)
7、启动PWM通道,该函数在sct_pwm_15xx.h- /**
- * @brief Start the SCT PWM
- * @param pSCT : The base of SCT peripheral on the chip
- * @return None
- * @note This function must be called after all the
- * configuration is completed. Do not call Chip_SCTPWM_SetRate()
- * or Chip_SCTPWM_SetOutPin() after the SCT/PWM is started. Use
- * Chip_SCTPWM_Stop() to stop the SCT/PWM before reconfiguring,
- * Chip_SCTPWM_SetDutyCycle() can be called when the SCT/PWM is
- * running to change the DutyCycle.
- */
- STATIC INLINE void Chip_SCTPWM_Start(LPC_SCT_T *pSCT)
- {
- Chip_SCT_ClearControl(pSCT, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);
- }
复制代码
8、修改占空比,同步骤5
9、停止SCT/PWM(可选),在sct_pwm_15xx.h- /**
- * @brief Stop the SCT PWM
- * @param pSCT : The base of SCT peripheral on the chip
- * @return None
- */
- STATIC INLINE void Chip_SCTPWM_Stop(LPC_SCT_T *pSCT)
- {
- /* Stop SCT */
- Chip_SCT_SetControl(pSCT, SCT_CTRL_HALT_L | SCT_CTRL_HALT_H);
- /* Clear the counter */
- Chip_SCT_SetControl(pSCT, SCT_CTRL_CLRCTR_L | SCT_CTRL_CLRCTR_H);
- }
复制代码
|
|