cancel
Showing results for 
Search instead for 
Did you mean: 

Quadrature changes my frequency to random values.

EmbeddedPepe
Associate III

Hi,

I've been trying to have a output quadrature and I somehow managed to do it with this code.

 

void TIM3_Configuration_positive_quadrature(void)
{
	TIM_OCInitTypeDef TIM_OCInitStructure;
	int Period;
	Period = 1000 / 1; // 1 Hz - 1 second on, 1 second off duty

	TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
	TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
	TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
	TIM_OCInitStructure.TIM_Pulse = (Period * 1) / 4; // CH3 at 25%
	TIM_OC3Init(TIM3, &TIM_OCInitStructure);
	TIM_OCInitStructure.TIM_Pulse = (Period * 3) / 4; // CH4 at 75%, ie half cycle later
	TIM_OC4Init(TIM3, &TIM_OCInitStructure);
}

 

 I set the frequency to 1500 Hz and run the quadrature function above but when I do it I see the quadrature on the oscilloscope but the frequency changes value continuosly to random values (for example 340, 420, 383, 540 Hz and so on) and can't understand what causes it.

Any help is appreciated 🙂

3 REPLIES 3
Uwe Bonnes
Principal III

Look for fundamental problems in you setup. I doubt you set the frequency you expect. How did you measure? With a scope? Did you perhaps have aliasing?

I measure it with a scope and also have a software that displays the frequency set.

I double checked and I set the correct frequency but as soon as I call the function of the quadrature the frequency starts going crazy.

No aliasing.

EmbeddedPepe
Associate III

On the oscilloscope I see half of the frequency I set, after calling the quadrature function.