2016-08-04 10:50 PM
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
If some body can helpme the prevent this and obtain a clean signal i will apretiate it.
Thanks
2016-08-08 02:22 AM
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.