AnsweredAssumed Answered

Creating a square wave

Question asked by tom on Jul 11, 2011
Latest reply on Jun 5, 2014 by khan.saud
I'm an absolutly beginner in microcontrollers.
I want to create a simple square wave signal on STM32F103VB with
tim3, ch2, but nothing happens.
Can anybody tell me what I'm doing wrong?

Thanks
Tom


#define DEF_SPEED 140;
#define CCR1_Val  32768;

int main(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef TIM_OCInitStructure;

  // RCC/System clocks configuration
  RCC_Config();

  // Enable Timer3 clock and release reset
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);

  // map PC7 as TIM3-CH2
  GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7; //7
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // clock to 50MHz
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_PP;  // alternate function pull
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_PinRemapConfig(GPIO_FullRemap_TIM3, ENABLE); // ?!!!!!!!!!!

  // Time base configuration
  TIM_TimeBaseStructure.TIM_Period = 0xFF; // 8 bit resolution
  TIM_TimeBaseStructure.TIM_Prescaler = DEF_SPEED;       
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;    
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 
  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

  // Output Compare Toggle Mode configuration: Channel2
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;          
  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;  
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
  TIM_OC2Init(TIM3, &TIM_OCInitStructure);

  TIM_Cmd(TIM3,ENABLE);
 
  while (1) {}
}

Outcomes