Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use an oscilloscope to measure duty cycles. Suppose the default MSI clock is use

ID: 2082948 • Letter: U

Question

Use an oscilloscope to measure duty cycles. Suppose the default MSI clock is used, which is 2.097 MHz. a. What is the relationship between the system clock, the counter clock CK_CNT, the prescaler TIM4_PSC, and the pulse period measured? b. We want to keep TIM4_ARR fixed, but set TIM4_CCR1 to three different values, as listed below. How would you set up the ARR, PSC, and CCR register values? Calculate the duty measured and verify the correctness. Case 1: TIM4_CCR1 = 1/6 * (TIM4_ARR + 1) Case 2: TIM4__CCR1 = 1/3 * (TIM4_ARR + 1) Case 3: TIM4_CCR1 = 1/2 * (TIM4_ARR + 1)

Explanation / Answer

Pulse counter

In some applications the microcontroller needs to keep track of some external events, but it

is not desirable to wake it up from stop mode

with each of them. In

this case, the LPTIM

configured as pulse counter comes in handy. Use the timer period/compare setting to set

the number of events required to wake the microcontroller.

To configure the timer in this mode:

1.

Configure a clock source.

2. Code the interrupt handler callback function and enable the LPTIM interrupt.

3. Setup the LPTIM timer peripheral:

a) Clock source and counter source selection. Only input1 can be used as a clock

source.

b) Typical configuration selection is immediate update mode and software trigger

source.

4. Enable and start the timer.

5. Go to Stop mode.

For more details on using the

timer in this mode, refer to the examples provided in the

STM32Cube package in the ExamplesL

PTIMLPTIM_PulseCo

unter subfolder.