Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
162
Добавлен:
01.03.2016
Размер:
3.56 Mб
Скачать

RM0016

16-bit advanced control timer (TIM1)

 

 

Figure 68. Detailed output stage of channel with complementary output (channel 1)

ETR

 

 

 

 

0

 

Output

TIM1_CH1

 

 

 

 

 

 

 

 

 

 

 

 

 

‘0’

 

 

 

Enable

 

 

 

 

 

x0

1

 

Circuit

 

 

 

 

 

 

 

 

 

 

 

 

 

01

 

 

 

 

 

 

 

 

OC1_DT

11

CC1P

 

 

 

Counter > CCR1

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

OC1REF

 

 

 

 

 

 

 

Counter = CCR1

Output Mode

Deadtime

 

 

TIM1_CCER1

 

 

Controller

 

Generator

OC1N_DT

 

 

 

 

 

 

 

 

 

11

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

10

0

 

Output

TIM1_CH1N

 

 

 

 

‘0’

 

 

 

 

 

 

 

 

0x

 

 

Enable

 

 

 

 

 

 

 

1

 

Circuit

 

 

 

 

 

 

 

 

 

CC1NE CC1E TIM1_CCER1

 

OC1M[2:0]

 

DTG[7:0]

CC1NE CC1E

CC1NP

MOE OSSI OSSR TIM1_BKR

 

TIM1_CCMR1

 

TIM1_DTR

TIM1_CCER1

TIM1_CCER1

OIS1N OIS1

TIM1_OISR

 

 

 

 

 

 

 

 

17.5.5Forced output mode

In output mode (CCiS bits = 00 in the TIM1_CCMRi registers), each output compare signal can be forced to high or low level directly by software, independently of any comparison between the output compare register and the counter.

To force an output compare signal to its active level, write 101 in the OCiM bits in the corresponding TIM1_CCMRi registers. OCiREF is forced high (OCiREF is always active high) and the OCi output is forced high or low depending on the CCiP polarity bits.

For example, if CCiP = 0 (OCi active high) => OCi is forced high.

The OCiREF signal can be forced low by writing the OCiM bits to 100 in the TIMx_CCMRx registers.

Nevertheless, the comparison between the TIM1_CCRi shadow registers and the counter is still performed and allows the flag to be set. Interrupt requests can be sent accordingly. This is described in the output compare mode section below.

17.5.6Output compare mode

This function is used to control an output waveform or indicate when a period of time has elapsed.

When a match is found between the capture/compare register and the counter:

Depending on the output compare mode, the corresponding OCi output pin:

Keeps its level (OCiM = 000),

Is set active (OCiM = 001),

Is set inactive (OCiM = 010)

Toggles (OCiM = 011)

A flag is set in the interrupt status register (CCiIF bits in the TIM1_SR1 register).

An interrupt is generated if the corresponding interrupt mask is set (CCiIE bits in the TIM1_IER register).

Doc ID 14587 Rev 9

169/454

16-bit advanced control timer (TIM1)

RM0016

 

 

The output compare mode is defined by the OCiM bits in the TIM1_CCMRi registers. The active or inactive level polarity is defined by the CCiP bits in the TIM1_CCERi registers.

The TIM1_CCRi registers can be programmed with or without preload registers using the OCiPE bits in the TIM1_CCMRi registers.

In output compare mode, the UEV has no effect on the OCiREF and OCi output. The timing resolution is one count of the counter. Output compare mode can also be used to output a single pulse.

Procedure

1.Select the counter clock (internal, external, or prescaler).

2.Write the desired data in the TIM1_ARR and TIM1_CCRi registers.

3.Set the CCiIE bits if an interrupt request is to be generated.

4.Select the output mode as follows:

Write OCiM = 011 to toggle the OCi output pin when CNT matches CCRi

Write OCiPE = 0 to disable the preload register

Write CCiP = 0 to select active high polarity

Write CCiE = 1 to enable the output

5.Enable the counter by setting the CEN bit in the TIMx_CR1 register

The TIM1_CCRi registers can be updated at any time by software to control the output waveform, provided that the preload registers are not enabled (OCiPE = 0). Otherwise, the TIMx_CCRi shadow registers are updated only at the next UEV (see example in Figure 69.

Figure 69. Output compare mode, toggle on OC1

 

 

 

 

Write B201h in the CC1R register

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TIMx_CNT

0039

 

003A

 

 

003B

B200

 

B201

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

TIMx_CCR1

 

 

 

003A

 

 

B201

 

 

 

 

OC1REF=OC1

Match detected on OCR1

Interrupt generated if enabled

170/454

Doc ID 14587 Rev 9

Соседние файлы в папке Минимум документации STM8_1