100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > MSP430F5529 DriverLib 库函数学习笔记(七)定时器B

MSP430F5529 DriverLib 库函数学习笔记(七)定时器B

时间:2021-05-28 22:43:22

相关推荐

MSP430F5529 DriverLib 库函数学习笔记(七)定时器B

目录

硬知识Timer_B特点及结构Timer_B寄存器定时器B API处理计时器配置和控制的函数参数处理计时器输出的函数参数管理定时器B中断的函数参数

平台:Code Composer Studio 10.3.1

MSP430F5529 LaunchPad™ Development Kit

(MSP‑EXP430F5529LP)


硬知识

16位定时器B(Timer_B)和Timer_A一样,是MSP430单片机的重要资源。Timer_B往往比Timer_A功能更强大一些,MSP430F5529单片机的Timer_B定时器具有7个捕获/比较寄存器。

Timer_B特点及结构

Timer_B定时器具有以下特点:

 具有4种工作模式和4种可选计数长度的异步16位定时/计数器;

 参考时钟源可配置;

 高达7个可配置的捕获/比较寄存器;

 具有PWM输出能力;

 具有同步加载能力的双缓冲区比较锁存;

 具有可对Timer_B中断快速响应的中断向量寄存器。

Timer_B和Timer_A的不同之处列举如下:

① Timer_B计数长度为8位、10位、12位和16位可编程,而Timer_A的计数长度固定为16位。

② Timer_B没有实现Timer_A中的SCCI寄存器位的功能。

③ Timer_B在比较模式下的捕获/比较寄存器功能与Timer_A的不同,增加了比较锁存器。

④ 有些型号芯片中的Timer_B输出实现了高阻抗输出。

⑤ 比较模式的原理有所不同。在Timer_A中,CCRx寄存器中保存与TAR相比较的数据,而在Timer_B中,CCRx寄存器中保存的是要比较的数据,但并不直接与定时计数器TBR相比较,而是将CCRx送到与之相对应的锁存器之后,由锁存器与定时计数器TBR相比较。从捕获/比较寄存器向比较锁存器传输数据的时机也是可以编程的,可以是在写入捕获/比较寄存器后立即传输,也可以由一个定时事件来触发。

⑥ Timer_B支持多种、同步的定时功能,多重的捕获/比较功能和多重的波形输出功能。而且通过对比较数据的两级缓冲,可以实现多个PWM信号周期的同步更新。

Timer_B寄存器

Timer_B寄存器列表如表所示,基址为03C0h。

定时器B API

TIMER_B API被分成三组函数:

处理计时器配置和控制的函数、

处理计时器输出的函数

处理中断处理的函数

处理计时器配置和控制的函数

Timer_B_startCounter(uint16_t baseAddress, uint16_t timerMode)//开启定时器Timer_B_initUpMode(uint16_t baseAddress, Timer_B_initUpModeParam ∗param)//配置Timer_B为增计数模式Timer_B_initUpDownMode(uint16_t baseAddress, Timer_B_initUpDownModeParam ∗param)//配置Timer_B为增/减计数模式Timer_B_initContinuousMode(uint16_t baseAddress, Timer_B_initContinuousModeParam ∗param)//配置Timer_B为连续计数模式Timer_B_initCaptureMode(uint16_t baseAddress, Timer_B_initCaptureModeParam ∗param)//初始化捕获模式Timer_B_initCompareMode(uint16_t baseAddress, Timer_B_initCompareModeParam ∗param)//初始化比较模式Timer_B_clear(uint16_t baseAddress)//重置/清除计时器、时钟分频器,计数方向,计数。Timer_B_stop()//停止Timer_BTimer_B_initCompareLatchLoadEvent(uint16_t baseAddress, uint16_t compareRegister, uint16_t compareLatchLoadEvent)//Selects Compare Latch Load Event.Timer_B_selectLatchingGroup(uint16_t baseAddress, uint16_t groupLatch)//Selects Timer_B Latching Group.Timer_B_selectCounterLength(uint16_t baseAddress, uint16_t counterLength)//选择Timer_B计数器长度(位数)

参数

baseAddress

TIMER_B0_BASE

timerMode

TIMER_B_STOP_MODETIMER_B_UP_MODETIMER_B_CONTINUOUS_MODE //[Default]TIMER_B_UPDOWN_MODE

Timer_B_initUpModeParam

//*****************************************************************************////! \brief Used in the Timer_B_initUpMode() function as the param parameter.////*****************************************************************************typedef struct Timer_B_initUpModeParam {//! Selects the clock source//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_EXTERNAL_TXCLK [Default]//! - \b TIMER_B_CLOCKSOURCE_ACLK//! - \b TIMER_B_CLOCKSOURCE_SMCLK//! - \b TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLKuint16_t clockSource;//! Is the divider for Clock source.//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_DIVIDER_1 [Default]//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_2//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_3//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_4//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_5//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_6//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_7//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_8//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_10//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_12//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_14//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_16//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_20//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_24//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_28//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_32//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_40//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_48//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_56//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_64uint16_t clockSourceDivider;//! Is the specified Timer_B period. This is the value that gets written//! into the CCR0. Limited to 16 bits[uint16_t]uint16_t timerPeriod;//! Is to enable or disable Timer_B interrupt//! \n Valid values are://! - \b TIMER_B_TBIE_INTERRUPT_ENABLE//! - \b TIMER_B_TBIE_INTERRUPT_DISABLE [Default]uint16_t timerInterruptEnable_TBIE;//! Is to enable or disable Timer_B CCR0 capture compare interrupt.//! \n Valid values are://! - \b TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE//! - \b TIMER_B_CCIE_CCR0_INTERRUPT_DISABLE [Default]uint16_t captureCompareInterruptEnable_CCR0_CCIE;//! Decides if Timer_B clock divider, count direction, count need to be//! reset.//! \n Valid values are://! - \b TIMER_B_DO_CLEAR//! - \b TIMER_B_SKIP_CLEAR [Default]uint16_t timerClear;//! Whether to start the timer immediatelybool startTimer;} Timer_B_initUpModeParam;

Timer_B_initUpDownModeParam

//*****************************************************************************////! \brief Used in the Timer_B_initUpDownMode() function as the param//! parameter.////*****************************************************************************typedef struct Timer_B_initUpDownModeParam {//! Selects the clock source//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_EXTERNAL_TXCLK [Default]//! - \b TIMER_B_CLOCKSOURCE_ACLK//! - \b TIMER_B_CLOCKSOURCE_SMCLK//! - \b TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLKuint16_t clockSource;//! Is the divider for Clock source.//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_DIVIDER_1 [Default]//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_2//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_3//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_4//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_5//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_6//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_7//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_8//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_10//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_12//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_14//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_16//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_20//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_24//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_28//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_32//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_40//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_48//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_56//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_64uint16_t clockSourceDivider;//! Is the specified Timer_B perioduint16_t timerPeriod;//! Is to enable or disable Timer_B interrupt//! \n Valid values are://! - \b TIMER_B_TBIE_INTERRUPT_ENABLE//! - \b TIMER_B_TBIE_INTERRUPT_DISABLE [Default]uint16_t timerInterruptEnable_TBIE;//! Is to enable or disable Timer_B CCR0 capture compare interrupt.//! \n Valid values are://! - \b TIMER_B_CCIE_CCR0_INTERRUPT_ENABLE//! - \b TIMER_B_CCIE_CCR0_INTERRUPT_DISABLE [Default]uint16_t captureCompareInterruptEnable_CCR0_CCIE;//! Decides if Timer_B clock divider, count direction, count need to be//! reset.//! \n Valid values are://! - \b TIMER_B_DO_CLEAR//! - \b TIMER_B_SKIP_CLEAR [Default]uint16_t timerClear;//! Whether to start the timer immediatelybool startTimer;} Timer_B_initUpDownModeParam;

Timer_B_initContinuousModeParam

//*****************************************************************************////! \brief Used in the Timer_B_initContinuousMode() function as the param//! parameter.////*****************************************************************************typedef struct Timer_B_initContinuousModeParam {//! Selects the clock source//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_EXTERNAL_TXCLK [Default]//! - \b TIMER_B_CLOCKSOURCE_ACLK//! - \b TIMER_B_CLOCKSOURCE_SMCLK//! - \b TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLKuint16_t clockSource;//! Is the divider for Clock source.//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_DIVIDER_1 [Default]//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_2//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_3//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_4//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_5//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_6//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_7//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_8//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_10//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_12//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_14//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_16//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_20//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_24//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_28//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_32//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_40//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_48//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_56//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_64uint16_t clockSourceDivider;//! Is to enable or disable Timer_B interrupt//! \n Valid values are://! - \b TIMER_B_TBIE_INTERRUPT_ENABLE//! - \b TIMER_B_TBIE_INTERRUPT_DISABLE [Default]uint16_t timerInterruptEnable_TBIE;//! Decides if Timer_B clock divider, count direction, count need to be//! reset.//! \n Valid values are://! - \b TIMER_B_DO_CLEAR//! - \b TIMER_B_SKIP_CLEAR [Default]uint16_t timerClear;//! Whether to start the timer immediatelybool startTimer;} Timer_B_initContinuousModeParam;

Timer_B_initCaptureModeParam

//*****************************************************************************////! \brief Used in the Timer_B_initCaptureMode() function as the param//! parameter.////*****************************************************************************typedef struct Timer_B_initCaptureModeParam {//! Selects the capture register being used. Refer to datasheet to ensure//! the device has the capture register being used.//! \n Valid values are://! - \b TIMER_B_CAPTURECOMPARE_REGISTER_0//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_1//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_2//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_3//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_4//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_5//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_6uint16_t captureRegister;//! Is the capture mode selected.//! \n Valid values are://! - \b TIMER_B_CAPTUREMODE_NO_CAPTURE [Default]//! - \b TIMER_B_CAPTUREMODE_RISING_EDGE//! - \b TIMER_B_CAPTUREMODE_FALLING_EDGE//! - \b TIMER_B_CAPTUREMODE_RISING_AND_FALLING_EDGEuint16_t captureMode;//! Decides the Input Select//! \n Valid values are://! - \b TIMER_B_CAPTURE_INPUTSELECT_CCIxA [Default]//! - \b TIMER_B_CAPTURE_INPUTSELECT_CCIxB//! - \b TIMER_B_CAPTURE_INPUTSELECT_GND//! - \b TIMER_B_CAPTURE_INPUTSELECT_Vccuint16_t captureInputSelect;//! Decides if capture source should be synchronized with Timer_B clock//! \n Valid values are://! - \b TIMER_B_CAPTURE_ASYNCHRONOUS [Default]//! - \b TIMER_B_CAPTURE_SYNCHRONOUSuint16_t synchronizeCaptureSource;//! Is to enable or disable Timer_B capture compare interrupt.//! \n Valid values are://! - \b TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE [Default]//! - \b TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLEuint16_t captureInterruptEnable;//! Specifies the output mode.//! \n Valid values are://! - \b TIMER_B_OUTPUTMODE_OUTBITVALUE [Default]//! - \b TIMER_B_OUTPUTMODE_SET//! - \b TIMER_B_OUTPUTMODE_TOGGLE_RESET//! - \b TIMER_B_OUTPUTMODE_SET_RESET//! - \b TIMER_B_OUTPUTMODE_TOGGLE//! - \b TIMER_B_OUTPUTMODE_RESET//! - \b TIMER_B_OUTPUTMODE_TOGGLE_SET//! - \b TIMER_B_OUTPUTMODE_RESET_SETuint16_t captureOutputMode;} Timer_B_initCaptureModeParam;

Timer_B_initCompareModeParam

//*****************************************************************************////! \brief Used in the Timer_B_initCompareMode() function as the param//! parameter.////*****************************************************************************typedef struct Timer_B_initCompareModeParam {//! Selects the compare register being used. Refer to datasheet to ensure//! the device has the compare register being used.//! \n Valid values are://! - \b TIMER_B_CAPTURECOMPARE_REGISTER_0//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_1//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_2//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_3//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_4//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_5//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_6uint16_t compareRegister;//! Is to enable or disable Timer_B capture compare interrupt.//! \n Valid values are://! - \b TIMER_B_CAPTURECOMPARE_INTERRUPT_DISABLE [Default]//! - \b TIMER_B_CAPTURECOMPARE_INTERRUPT_ENABLEuint16_t compareInterruptEnable;//! Specifies the output mode.//! \n Valid values are://! - \b TIMER_B_OUTPUTMODE_OUTBITVALUE [Default]//! - \b TIMER_B_OUTPUTMODE_SET//! - \b TIMER_B_OUTPUTMODE_TOGGLE_RESET//! - \b TIMER_B_OUTPUTMODE_SET_RESET//! - \b TIMER_B_OUTPUTMODE_TOGGLE//! - \b TIMER_B_OUTPUTMODE_RESET//! - \b TIMER_B_OUTPUTMODE_TOGGLE_SET//! - \b TIMER_B_OUTPUTMODE_RESET_SETuint16_t compareOutputMode;//! Is the count to be compared with in compare modeuint16_t compareValue;} Timer_B_initCompareModeParam;

compareRegister

/*selects the compare register being used. Refer to datasheet toensure the device has the compare register being used. Validvalues are:*/TIMER_B_CAPTURECOMPARE_REGISTER_0TIMER_B_CAPTURECOMPARE_REGISTER_1TIMER_B_CAPTURECOMPARE_REGISTER_2TIMER_B_CAPTURECOMPARE_REGISTER_3TIMER_B_CAPTURECOMPARE_REGISTER_4TIMER_B_CAPTURECOMPARE_REGISTER_5TIMER_B_CAPTURECOMPARE_REGISTER_6

compareLatchLoadEvent

/*selects the latch load event Valid values are:*/TIMER_B_LATCH_ON_WRITE_TO_TBxCCRn_COMPARE_REGISTER//[Default]TIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_0_IN_UP_OR_CONT_MODETIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_0_IN_UPDOWN_MODETIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_CURRENT_COMPARE_LATCH_VALUE

groupLatch

//selects the latching group. Valid values are:TIMER_B_GROUP_NONE //[Default]TIMER_B_GROUP_CL12_CL23_CL56TIMER_B_GROUP_CL123_CL456TIMER_B_GROUP_ALL

counterLength

//selects the value of counter length. Valid values are:TIMER_B_COUNTER_16BIT//[Default]TIMER_B_COUNTER_12BITTIMER_B_COUNTER_10BITTIMER_B_COUNTER_8BIT

处理计时器输出的函数

Timer_B_getSynchronizedCaptureCompareInput(uint16_t baseAddress, uint16_t captureCompareRegister, uint16_t synchronized)//获取同步的capturecompare输入Timer_B_getOutputForOutputModeOutBitValue(uint16_t baseAddress, uint16_t captureCompareRegister)//为输出模式获取输出位Timer_B_setOutputForOutputModeOutBitValue(uint16_t baseAddress, uint16_t captureCompareRegister, uint16_t outputModeOutBitValue)//为输出模式设置输出位Timer_B_outputPWM(uint16_t baseAddress, Timer_B_outputPWMParam ∗param)//通过增计数模式产生PWM信号Timer_B_getCaptureCompareCount(uint16_t baseAddress, uint16_t captureCompareRegister)//获取当前capturecompare计数Timer_B_setCompareValue(uint16_t baseAddress, uint16_t compareRegister, uint16_t compareValue)//设置捕获比较寄存器的值Timer_B_getCounterValue(uint16_t baseAddress)//读取当前计时器计数值

参数

baseAddress

TIMER_B0_BASE

captureCompareRegister

/*selects the capture compare register being used. Refer todatasheet to ensure the device has the capture compare registerbeing used. Valid values are:*/TIMER_B_CAPTURECOMPARE_REGISTER_0TIMER_B_CAPTURECOMPARE_REGISTER_1TIMER_B_CAPTURECOMPARE_REGISTER_2TIMER_B_CAPTURECOMPARE_REGISTER_3TIMER_B_CAPTURECOMPARE_REGISTER_4TIMER_B_CAPTURECOMPARE_REGISTER_5TIMER_B_CAPTURECOMPARE_REGISTER_6

synchronized

//selects the type of capture compare input Valid values are:TIMER_B_READ_SYNCHRONIZED_CAPTURECOMPAREINPUTTIMER_B_READ_CAPTURE_COMPARE_INPUT

outputModeOutBitValue

//the value to be set for out bit Valid values are:TIMER_B_OUTPUTMODE_OUTBITVALUE_HIGHTIMER_B_OUTPUTMODE_OUTBITVALUE_LOW

Timer_B_outputPWMParam

//*****************************************************************************////! \brief Used in the Timer_B_outputPWM() function as the param parameter.////*****************************************************************************typedef struct Timer_B_outputPWMParam {//! Selects the clock source//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_EXTERNAL_TXCLK [Default]//! - \b TIMER_B_CLOCKSOURCE_ACLK//! - \b TIMER_B_CLOCKSOURCE_SMCLK//! - \b TIMER_B_CLOCKSOURCE_INVERTED_EXTERNAL_TXCLKuint16_t clockSource;//! Is the divider for Clock source.//! \n Valid values are://! - \b TIMER_B_CLOCKSOURCE_DIVIDER_1 [Default]//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_2//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_3//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_4//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_5//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_6//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_7//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_8//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_10//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_12//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_14//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_16//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_20//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_24//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_28//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_32//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_40//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_48//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_56//! - \b TIMER_B_CLOCKSOURCE_DIVIDER_64uint16_t clockSourceDivider;//! Selects the desired Timer_B perioduint16_t timerPeriod;//! Selects the compare register being used. Refer to datasheet to ensure//! the device has the compare register being used.//! \n Valid values are://! - \b TIMER_B_CAPTURECOMPARE_REGISTER_0//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_1//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_2//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_3//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_4//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_5//! - \b TIMER_B_CAPTURECOMPARE_REGISTER_6uint16_t compareRegister;//! Specifies the output mode.//! \n Valid values are://! - \b TIMER_B_OUTPUTMODE_OUTBITVALUE [Default]//! - \b TIMER_B_OUTPUTMODE_SET//! - \b TIMER_B_OUTPUTMODE_TOGGLE_RESET//! - \b TIMER_B_OUTPUTMODE_SET_RESET//! - \b TIMER_B_OUTPUTMODE_TOGGLE//! - \b TIMER_B_OUTPUTMODE_RESET//! - \b TIMER_B_OUTPUTMODE_TOGGLE_SET//! - \b TIMER_B_OUTPUTMODE_RESET_SETuint16_t compareOutputMode;//! Specifies the dutycycle for the generated waveformuint16_t dutyCycle;} Timer_B_outputPWMParam;

compareRegister

//selects the compare register being used. Refer to datasheet to ensure the device has the compare register being used. Valid values are:TIMER_B_CAPTURECOMPARE_REGISTER_0TIMER_B_CAPTURECOMPARE_REGISTER_1TIMER_B_CAPTURECOMPARE_REGISTER_2TIMER_B_CAPTURECOMPARE_REGISTER_3TIMER_B_CAPTURECOMPARE_REGISTER_4TIMER_B_CAPTURECOMPARE_REGISTER_5TIMER_B_CAPTURECOMPARE_REGISTER_6

compareValue

比较模式下需要比较的计数值

管理定时器B中断的函数

Timer_B_enableInterrupt(uint16_t baseAddress)//使能定时器B中断Timer_B_disableInterrupt(uint16_t baseAddress)//禁用定时器B中断Timer_B_getInterruptStatus(uint16_t baseAddress)//获取定时器B中断状态Timer_B_enableCaptureCompareInterrupt(uint16_t baseAddress, uint16_t captureCompareRegister)//启用捕获比较中断Timer_B_disableCaptureCompareInterrupt(uint16_t baseAddress, uint16_t captureCompareRegister)//禁用捕获比较中断Timer_B_getCaptureCompareInterruptStatus(uint16_t baseAddress, uint16_t captureCompareRegister, uint16_t mask)//清除捕获比较中断标志Timer_B_clearCaptureCompareInterrupt(uint16_t baseAddress, uint16_t captureCompareRegister)//清除捕获比较中断标志Timer_B_clearTimerInterrupt(uint16_t baseAddress)//清除Timer_ B TBIFG中断标志。

参数

baseAddress

TIMER_B0_BASE

captureCompareRegister

/*selects the capture compare register being used. Refer todatasheet to ensure the device has the capture compare registerbeing used. Valid values are:*/TIMER_B_CAPTURECOMPARE_REGISTER_0TIMER_B_CAPTURECOMPARE_REGISTER_1TIMER_B_CAPTURECOMPARE_REGISTER_2TIMER_B_CAPTURECOMPARE_REGISTER_3TIMER_B_CAPTURECOMPARE_REGISTER_4TIMER_B_CAPTURECOMPARE_REGISTER_5TIMER_B_CAPTURECOMPARE_REGISTER_6

mask

/*is the mask for the interrupt status Mask value is the logical OR ofany of the following:*/TIMER_B_CAPTURE_OVERFLOWTIMER_B_CAPTURECOMPARE_INTERRUPT_FLAG

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。