AnsweredAssumed Answered

pwm generation problem stm32f303

Question asked by la_marca.giuseppe on Jun 11, 2016
Latest reply on Jun 11, 2016 by la_marca.giuseppe
Hi to all, I'm giuseppe and I'm new here, 
I've a big problem with the generation of pwm signal, in the code below i'm trying to create a pwm of 50% duty cycle in port PA0, the pwm would be of a period of 1s, so i can try it over a led, in many instructions I don't know what i'm doing but I'm just trying to do what the refman says, so any help would be really appreciated. 
#include "stm32f30x.h"
#include "startup_stm32f30x.s"
int cnt=0;
int main()
{
   RCC->APB1ENR |= 1<<0;                                                        //clock for TIM2
  RCC->AHBENR |= 1<<17;                                                         //clock for GPIOA
  GPIOA->MODER |= 3<<0;                                                         //select alternative function over A port
  GPIOA->AFR[0] = 0x0;
  TIM2->PSC=0;
  TIM2->ARR=72000000;                                                           // 1 second period
  TIM2->CNT=0;
   
  TIM2->CR1 |= 1<<7;                           
  TIM2->CCR1= 36000000;                                                         //0.5 second 
   
  TIM2->CCER |= 1<<0;                                                           //set the CC1E bit
  TIM2->EGR = 1<<0;                                                             //set the UEG bit
  TIM2->CCMR1 |= 3<<5;
  TIM2->CCMR1 |= 1<<3;
    TIM2->DIER |= 1<<1;
    TIM2->CR1 |=1<<0                                     //start the timer
 
 
  while(1);
  //return 0;
}

Outcomes