Codice:
include "stm32f10x.h" // Device header
void pwm_init()
{
/**********************TIM4 CH1 PWM PB6************************** */
RCC->APB2ENR |= (1<<3); /* GPIOB Clock enable */
RCC->APB1ENR |= ()1<<2); /* TIM4 Clock enable */
GPIOB->CRL &= 0xF0FFFFFF;/*PB6 clear*/
GPIOB->CRL |= 0x0B000000;/* Alternate function output Push-pull Output */
TIM4->ARR = 49999; // 72000000 /50000 = 1440Hz
TIM4->PSC = 0; //Prescaler
TIM4->CCMR1 |= 0x0078; //Output compare 1 preload enable pwm2 mode
TIM4->CCER |= 0x0001; //Capture/Compare 1 output enable
TIM4->EGR |= 0x0001;//Update generation
TIM4->CCR1 = TIM4->ARR/2; //Duty %50
TIM4->CR1 |= 0x0081;//Auto-reload preload enable Timer enable
}
int main()
{
pwm_init();
while(1)
{
}
}