MSP430F5529 DriverLib library function learning note timer B

Platform: Code Composer Studio 10.3.1
MSP430F5529 LaunchPad™ Development Kit
(MSP‑EXP430F5529LP)

Hard knowledge

16 bit timer B(Timer_B) and timer_ Like a, it is an important resource of MSP430 MCU. Timer_ B is often better than Timer_A more powerful, MSP430F5529 MCU timer_ The B timer has 7 capture / compare registers.

Timer_B. features and structure

       Timer_B timer has the following features:
 asynchronous 16 bit timing / counter with 4 working modes and 4 optional counting lengths;
 the reference clock source can be configured;
 up to 7 configurable capture / comparison registers;
 PWM output capability;
 double buffer comparison latch with synchronous loading capability;
 timer can be_ B interrupt vector register for fast interrupt response.

Timer_B and timer_ The differences of a are listed as follows:
① Timer_B count length is 8 bits, 10 bits, 12 bits and 16 bits programmable, while timer_ The counting length of a is fixed to 16 bits.
② Timer_B does not implement timer_ Function of SCCI register bit in a.
③ Timer_B capture / compare register function and timer in comparison mode_ A is different, and a comparison latch is added.
④ Timers in some models of chips_ B output realizes high impedance output.
⑤ The principle of comparison mode is different. In timer_ In a, the CCRx register stores the data compared with TAR, and in timer_ In B, the data to be compared is stored in the CCRx register, but it is not directly compared with the timing counter TBR. After CCRx is sent to the corresponding latch, the latch is compared with the timing counter TBR. The timing of transmitting data from the capture / comparison register to the comparison latch can also be programmed, which can be transmitted immediately after writing to the capture / comparison register, or triggered by a timing event.
⑥ Timer_B supports multiple synchronous timing functions, multiple capture / comparison functions and multiple waveform output functions. Moreover, through the two-stage buffer of the comparison data, the synchronous update of multiple PWM signal cycles can be realized.

Timer_B register

Timer_ The list of B registers is shown in the table, and the base address is 03C0h.

Timer B API

TIMER_ The B API is divided into three groups of functions:
Functions that handle timer configuration and control
Functions that handle timer output
Functions that handle interrupt handling

Functions that handle timer configuration and control

Timer_B_startCounter(uint16_t baseAddress, uint16_t timerMode)
//Turn on the timer
Timer_B_initUpMode(uint16_t baseAddress, Timer_B_initUpModeParam ∗param)
//Configure Timer_B is increment count mode
Timer_B_initUpDownMode(uint16_t baseAddress, Timer_B_initUpDownModeParam ∗param)
//Configure Timer_B is the increase / decrease count mode
Timer_B_initContinuousMode(uint16_t baseAddress, Timer_B_initContinuousModeParam ∗param)
//Configure Timer_B is continuous counting mode
Timer_B_initCaptureMode(uint16_t baseAddress, Timer_B_initCaptureModeParam ∗param)
//Initialize capture mode
Timer_B_initCompareMode(uint16_t baseAddress, Timer_B_initCompareModeParam ∗param)
//Initialize comparison mode
Timer_B_clear(uint16_t baseAddress)
//Reset / clear timer, clock divider, counting direction, counting.
Timer_B_stop()
//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)
//Select Timer_B counter length (digits)

parameter

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_TXCLK
    uint16_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_64
    uint16_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 immediately
    bool 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_TXCLK
    uint16_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_64
    uint16_t clockSourceDivider;
    //! Is the specified Timer_B period
    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 immediately
    bool 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_TXCLK
    uint16_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_64
    uint16_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 immediately
    bool 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_6
    uint16_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_EDGE
    uint16_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_Vcc
    uint16_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_SYNCHRONOUS
    uint16_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_ENABLE
    uint16_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_SET
    uint16_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_6
    uint16_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_ENABLE
    uint16_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_SET
    uint16_t compareOutputMode;
    //! Is the count to be compared with in compare mode
    uint16_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

Functions that handle timer output

Timer_B_getSynchronizedCaptureCompareInput(uint16_t baseAddress, uint16_t captureCompareRegister, uint16_t synchronized)
//Get synchronized capturecompare input
Timer_B_getOutputForOutputModeOutBitValue(uint16_t baseAddress, uint16_t captureCompareRegister)
//Gets the output bit for the output mode
Timer_B_setOutputForOutputModeOutBitValue(uint16_t baseAddress, uint16_t captureCompareRegister, uint16_t outputModeOutBitValue)
//Sets the output bit for the output mode
Timer_B_outputPWM(uint16_t baseAddress, Timer_B_outputPWMParam ∗param)
//The PWM signal is generated by increasing the count mode
Timer_B_getCaptureCompareCount(uint16_t baseAddress, uint16_t captureCompareRegister)
//Gets the current capturecompare count
Timer_B_setCompareValue(uint16_t baseAddress, uint16_t compareRegister, uint16_t compareValue)
//Sets the value of the capture compare register
Timer_B_getCounterValue(uint16_t baseAddress)
//Read current timer count

parameter

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_TXCLK
    uint16_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_64
    uint16_t clockSourceDivider;
    //! Selects the desired Timer_B period
    uint16_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_6
    uint16_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_SET
    uint16_t compareOutputMode;
    //! Specifies the dutycycle for the generated waveform
    uint16_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
Count value to be compared in comparison mode

Function to manage timer B interrupt

Timer_B_enableInterrupt(uint16_t baseAddress)
//Enable timer B interrupt
Timer_B_disableInterrupt(uint16_t baseAddress)
//Disable timer B interrupt
Timer_B_getInterruptStatus(uint16_t baseAddress)
//Get timer B interrupt status
Timer_B_enableCaptureCompareInterrupt(uint16_t baseAddress, uint16_t captureCompareRegister)
//Enable capture compare interrupt
Timer_B_disableCaptureCompareInterrupt(uint16_t baseAddress, uint16_t captureCompareRegister)
//Disable capture comparison interrupt
Timer_B_getCaptureCompareInterruptStatus(uint16_t baseAddress, uint16_t captureCompareRegister, uint16_t mask)
//Clear capture comparison interrupt flag
Timer_B_clearCaptureCompareInterrupt(uint16_t baseAddress, uint16_t captureCompareRegister)
//Clear capture comparison interrupt flag
Timer_B_clearTimerInterrupt(uint16_t baseAddress)
//Clear Timer_ B TBIFG interrupt flag.

parameter

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

Keywords: C Embedded system Single-Chip Microcomputer MCU

Added by dasding on Fri, 14 Jan 2022 17:27:15 +0200