cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 Sweep frequency

woutnme
Associate II
Posted on August 05, 2016 at 07:50

Hi im newbie with this mcu, and im try to doing a sweep of frequency with TIM3 and the chanel1, A6. my main code its the next

while (1)
{
unsigned int i=0, j=0, h=0;
for(i = FrequencyStart; i < (FrequencyStart+FrequencySweep); i++){
Frequency = i;
TIM_TimeBaseStructure.TIM_Period = Frequency;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_Pulse = (Frequency/2);
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
for(j = 0; j < 
0x2AFF
; j++){;}
}
for(h = (FrequencyStart+FrequencySweep); h > FrequencyStart; h--){
Frequency = h;
TIM_TimeBaseStructure.TIM_Period = Frequency;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_Pulse = (Frequency/2);
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
for(j = 0; j < 0x2AFF; j++){;}
}
}

This make me the sweep frequency fine but the signal have a little errors around each 1370us look the photo 0690X00000602rDQAQ.jpg 0690X00000603AhQAI.jpg If some body can helpme the prevent this and obtain a clean signal i will apretiate it. Thanks
1 REPLY 1
troy1818
Senior
Posted on August 08, 2016 at 11:22

You will never get any stable oscillation when using a variable number of instructions between some oscillations.

The reason is that the code that you use also take some time to execute. I think you will see some change in the oscillation characteristic if you just turn on/off optimization for your code in order to verify my statement.