/* p11_6.c Dead time creation with TIM1 PWM * * In this program, TIM1 Ch1 and Ch1N are configured as complementary * outputs of the center-aligned PWM. The output of Ch1 is PA8 and * the output of Ch1N is PA7. * To exaggerate the dead time, the dead time clock is set to four * times the timer counter clock in TIM1_CR1 and the dead time value * is set to 16 times the dead time clock in TIM1_BDTR. * * This program was tested with Keil uVision v5.23 with DFP v2.0.0. */ #include "stm32f0xx.h" int main(void) { RCC->AHBENR |= 0x00020000; /* enable GPIOA clock */ GPIOA->AFR[1] |= 0x00000002; /* set pin for TIM1 Ch1 */ GPIOA->MODER &= ~0x00030000; GPIOA->MODER |= 0x00020000; GPIOA->AFR[0] |= 0x20000000; /* set pin for TIM1 Ch1N */ GPIOA->MODER &= ~0x0000C000; GPIOA->MODER |= 0x00008000; /* setup TIM1 */ RCC->APB2ENR |= 0x00000800; /* enable TIM1 clock */ TIM1->PSC = 8 - 1; /* divided by 8 */ TIM1->ARR = 1000; /* divided by 1000 */ TIM1->CNT = 0; TIM1->CCMR1 = 0x0060; TIM1->CCER = 5; /* enable PWM Ch1, Ch1N */ TIM1->CCR1 = 500; /* pulse width 500 */ TIM1->BDTR = 0x80D0; /* enable output, set dead time duration */ TIM1->CR1 = 0x221; /* slow DT clock, center-aligned, enable timer */ while(1) { } }