/* p11_6.c Dead time creation with TIM8 PWM * * In this program, TIM8 Ch1 and Ch1N are configured as complementary * outputs of the center-aligned PWM. The output of Ch1 is PC6 and * the output of Ch1N is PA5. * To exaggerate the dead time, the dead time clock is set to four * times the timer counter clock in TIM8_CR1 and the dead time value * is set to maximum in TIM8_BDTR. * * This program was tested with Keil uVision v5.24a with DFP v2.11.0 */ #include "stm32f4xx.h" int main(void) { RCC->AHB1ENR |= 5; /* enable GPIOA clock */ GPIOC->AFR[0] |= 0x03000000; /* set pin for tim8 Ch1 */ GPIOC->MODER &= ~0x00003000; GPIOC->MODER |= 0x00002000; GPIOA->AFR[0] |= 0x00300000; /* set pin for tim8 Ch1N */ GPIOA->MODER &= ~0x00000C00; GPIOA->MODER |= 0x00000800; /* setup TIM8 */ RCC->APB2ENR |= 2; /* enable TIM8 clock */ TIM8->PSC = 16 - 1; /* divided by 16 */ TIM8->ARR = 1000; /* divided by 1000 */ TIM8->CNT = 0; TIM8->CCMR1 = 0x0060; TIM8->CCER = 5; /* enable PWM Ch1, Ch1N */ TIM8->CCR1 = 500 - 1; /* pulse width 500 */ TIM8->BDTR |= 0x80FF; /* enable output, set max dead time */ TIM8->CR1 = 0x221; /* slow DT clock, center-aligned, enable timer */ while(1) { } }