 Problem with Input Capture in MCBSTR9 Board
RajaRao Malkari
Hai all,
we are using MCBSTR9 Evaluation board.
Now we are trying to implement Input capture.
for that we generated a PWM signal from Timer0 and that signal is
applied to input capture pin of Timer2.
here we are getting PWM signal but we are not able to get the capture
value. i am testing this code through DEBUG. in my program i am not
getting INPUT CAPTURE FLAG. so my programis strucked there
itself.
here i am sending the code please have a glance of this program and
give u'r sugessions.
#include "91x_lib.h"
TIM_InitTypeDef TIM_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
u16 Cap_Val=0;
int main(void)
{ #ifdef DEBUG
debug();
#endif
SCU_APBPeriphClockConfig(__TIM01, ENABLE); /* Enable the clock for
TIM0 and TIM1 */
TIM_DeInit(TIM0); /* TIM0 Deinitialization */
SCU_APBPeriphClockConfig(__TIM23, ENABLE); /* Enable the clock for
TIM2 and TIM3 */
TIM_DeInit(TIM2); /* TIM2 Deinitialization */
SCU_APBPeriphClockConfig(__GPIO4, ENABLE); /* Enable the clock for
GPIO4 */
GPIO_DeInit(GPIO4); /* GPIO4 Deinitialization */
SCU_APBPeriphClockConfig(__GPIO6, ENABLE); /* Enable the clock for
GPIO6 */
GPIO_DeInit(GPIO6); /* GPIO6 Deinitialization */
SCU_APBPeriphClockConfig(__GPIO7, ENABLE); /* Enable the clock for
GPIO6 */
GPIO_DeInit(GPIO7); /* GPIO6 Deinitialization */
/* GPIO Structure Initialization */
GPIO_StructInit(&GPIO_InitStructure);
/* GPIO6 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2; //OCMP1
GPIO_Init(GPIO6,&GPIO_InitStructure);
/* GPIO7 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
//GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt1; // GPIO
GPIO_Init(GPIO7,&GPIO_InitStructure);
/* GPIO4 configuration */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Direction = GPIO_PinInput;
GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull;
GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;
GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; // ICAP1
GPIO_Init(GPIO4,&GPIO_InitStructure);
/* TIM0 Structure Initialization */
TIM_StructInit(&TIM_InitStructure);
/* TIM0 Configuration in PWM Mode */
TIM_InitStructure.TIM_Mode = TIM_PWM;
TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
TIM_InitStructure.TIM_Prescaler = 0xFF;
TIM_InitStructure.TIM_Pulse_Level_1 = TIM_HIGH;
TIM_InitStructure.TIM_Period_Level = TIM_LOW;
TIM_InitStructure.TIM_Pulse_Length_1 = 0xBFF;
TIM_InitStructure.TIM_Full_Period = 0xFFF;
TIM_Init (TIM0, &TIM_InitStructure);
/* Start the counter of TIM0 */
TIM_CounterCmd(TIM0, TIM_START);
/* TIM2 Structure Initialization */
TIM_StructInit(&TIM_InitStructure); /* TIM2 Configuration in CAP
Mode */
TIM_InitStructure.TIM_Mode = TIM_ICAP_CHANNEL_1;
TIM_InitStructure.TIM_ICAP1_Edge = TIM_ICAP1_EDGE_FALLING;
TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB;
TIM_InitStructure.TIM_Prescaler = 0xFF;
TIM_Init (TIM2, &TIM_InitStructure);
//TIM_ITConfig(TIM2, TIM_IT_IC1, ENABLE);
/* Start the counter of TIM2 */
TIM_CounterCmd(TIM2, TIM_START);
while(1)
{ while( TIM_GetFlagStatus(TIM2, TIM_FLAG_IC1) == RESET);
Cap_Val=TIM_GetICAP1Value(TIM2);
TIM_ClearFlag(TIM2, TIM_FLAG_IC1);
GPIO_Write(GPIO7,Cap_Val);
} }
|