This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Help with PWM Input on MCBSTM32

I have a MCBSTM32 board and I want to measure a frequency of an external signal applied on an input pin of the board. I read on the internet and on the ST official site about this but I can't resolve my problem. They give an example of that for another board, but how can I make it work for my board?
Here is the code:

/** ****************************************************************************** * @file TIM/PWM_Input/main.c * @author MCD Application Team * @version V3.1.2 * @date 09/28/2009 * @brief Main program body ****************************************************************************** * @copy * * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. * * <h2><center>© COPYRIGHT 2009 STMicroelectronics</center></h2> */

/* Includes ------------------------------------------------------------------*/
//#include "stm32f10x.h"

/** @addtogroup STM32F10x_StdPeriph_Examples * @{ */

/** @addtogroup TIM_PWM_Input * @{ */

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
TIM_ICInitTypeDef TIM_ICInitStructure;

/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);

/* Private functions ---------------------------------------------------------*/

/** * @brief Main program * @param None * @retval None */
int main(void)
{ /* System Clocks Configuration */ RCC_Configuration();

/* NVIC configuration */ NVIC_Configuration();

/* Configure the GPIO ports */ GPIO_Configuration();

/* TIM3 configuration: PWM Input mode ------------------------ The external signal is connected to TIM3 CH2 pin (PA.01), The Rising edge is used as active edge, The TIM3 CCR2 is used to compute the frequency value The TIM3 CCR1 is used to compute the duty cycle value ------------------------------------------------------------ */

TIM_ICInitStructure.TIM_Channel = TIM_Channel_2; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0;

TIM_PWMIConfig(TIM3, &TIM_ICInitStructure);

/* Select the TIM3 Input Trigger: TI2FP2 */ TIM_SelectInputTrigger(TIM3, TIM_TS_TI2FP2);

/* Select the slave Mode: Reset Mode */ TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_Reset);

/* Enable the Master/Slave Mode */ TIM_SelectMasterSlaveMode(TIM3, TIM_MasterSlaveMode_Enable);

/* TIM enable counter */ TIM_Cmd(TIM3, ENABLE);

/* Enable the CC2 Interrupt Request */ TIM_ITConfig(TIM3, TIM_IT_CC2, ENABLE);

while (1);
}

/** * @brief Configures the different system clocks. * @param None * @retval None */
void RCC_Configuration(void)
{ /* Setup the microcontroller system. Initialize the Embedded Flash Interface, initialize the PLL and update the SystemFrequency variable. */ SystemInit();

/* TIM3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

/* GPIOA clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
}

/** * @brief Configure the GPIOD Pins. * @param None * @retval None */
void GPIO_Configuration(void)
{ GPIO_InitTypeDef GPIO_InitStructure;

/* TIM3 channel 2 pin (PA.01) configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);
}

/** * @brief Configure the nested vectored interrupt controller. * @param None * @retval None */
void NVIC_Configuration(void)
{ NVIC_InitTypeDef NVIC_InitStructure;

/* Enable the TIM3 global Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);
}

#ifdef USE_FULL_ASSERT

/** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */
void assert_failed(uint8_t* file, uint32_t line)
{ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

while (1) {}
} #endif

/** * @} */

/** * @} */

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/

Parents
  • I admit that I'm new in this domain. I checked the datasheet and other examples for my board, but I'm stuck in doing that code working. The code was taken from the official site of STMicroelectronics, witch is a free code, it cames with the firmware for the controller that MCBSTM32 it has on it. If you can give me some indication about this or some ideas, where I can look for some answers, I'll be a happy man. Thank you for your interest in this.

Reply
  • I admit that I'm new in this domain. I checked the datasheet and other examples for my board, but I'm stuck in doing that code working. The code was taken from the official site of STMicroelectronics, witch is a free code, it cames with the firmware for the controller that MCBSTM32 it has on it. If you can give me some indication about this or some ideas, where I can look for some answers, I'll be a happy man. Thank you for your interest in this.

Children
No data