日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/9 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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_B Timer_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_MODE TIMER_B_UP_MODE TIMER_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 to ensure the device has the compare register being used. Valid values are: */ TIMER_B_CAPTURECOMPARE_REGISTER_0 TIMER_B_CAPTURECOMPARE_REGISTER_1 TIMER_B_CAPTURECOMPARE_REGISTER_2 TIMER_B_CAPTURECOMPARE_REGISTER_3 TIMER_B_CAPTURECOMPARE_REGISTER_4 TIMER_B_CAPTURECOMPARE_REGISTER_5 TIMER_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_MODE TIMER_B_LATCH_WHEN_COUNTER_COUNTS_TO_0_IN_UPDOWN_MODE TIMER_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_CL56 TIMER_B_GROUP_CL123_CL456 TIMER_B_GROUP_ALL

counterLength

//selects the value of counter length. Valid values are: TIMER_B_COUNTER_16BIT //[Default] TIMER_B_COUNTER_12BIT TIMER_B_COUNTER_10BIT TIMER_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 to datasheet to ensure the device has the capture compare register being used. Valid values are: */ TIMER_B_CAPTURECOMPARE_REGISTER_0 TIMER_B_CAPTURECOMPARE_REGISTER_1 TIMER_B_CAPTURECOMPARE_REGISTER_2 TIMER_B_CAPTURECOMPARE_REGISTER_3 TIMER_B_CAPTURECOMPARE_REGISTER_4 TIMER_B_CAPTURECOMPARE_REGISTER_5 TIMER_B_CAPTURECOMPARE_REGISTER_6

synchronized

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

outputModeOutBitValue

//the value to be set for out bit Valid values are: TIMER_B_OUTPUTMODE_OUTBITVALUE_HIGH TIMER_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_0 TIMER_B_CAPTURECOMPARE_REGISTER_1 TIMER_B_CAPTURECOMPARE_REGISTER_2 TIMER_B_CAPTURECOMPARE_REGISTER_3 TIMER_B_CAPTURECOMPARE_REGISTER_4 TIMER_B_CAPTURECOMPARE_REGISTER_5 TIMER_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 to datasheet to ensure the device has the capture compare register being used. Valid values are: */ TIMER_B_CAPTURECOMPARE_REGISTER_0 TIMER_B_CAPTURECOMPARE_REGISTER_1 TIMER_B_CAPTURECOMPARE_REGISTER_2 TIMER_B_CAPTURECOMPARE_REGISTER_3 TIMER_B_CAPTURECOMPARE_REGISTER_4 TIMER_B_CAPTURECOMPARE_REGISTER_5 TIMER_B_CAPTURECOMPARE_REGISTER_6

mask

/* is the mask for the interrupt status Mask value is the logical OR of any of the following: */ TIMER_B_CAPTURE_OVERFLOW TIMER_B_CAPTURECOMPARE_INTERRUPT_FLAG

總結

以上是生活随笔為你收集整理的MSP430F5529 DriverLib 库函数学习笔记(七)定时器B的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。