CodePudding user response:
The clock reference, such as different code to do the corresponding processing external crystals,CodePudding user response:
Can use the software simulation and debugging interface to run the program (note that set the crystal frequency, set SCM model), look at the delay time (there should be a place you can see the operation of the computer to calculate to a theory of time step, according to delay the start of the theory and the theory of time delay of the end of the time difference can be delay time), then according to the delay time adjustment process to achieve satisfied effect,About the automatic generation of delay is not allowed, I feel may be crystal didn't adjust the vibration frequency, or SCM model in conformity with delay generator set in,
CodePudding user response:
To see what factors caused by the delay is not accurate, many factors can cause time delay is not accurate, also associated with different time delay is directly in the application process;Such as the timer interrupt, timer timing is very accurate, but because wait for interrupt response, is in the time clock is not accurate, so the external clock module timing separately and then read its internal timer which will not affect the timing accuracy.
Below for chestnuts, clearly see delay affected by other delay, an extremely simple digital tube display a decreasing number of programs:
Void main ()
{
Unsigned int YS=54000, a=55555;
While (1)
{
A -;
YS=54000; While (YS) ZhengShuXianShi (8, a);/* integer resolution to the digital tube display from 8 bits to 1 */
}
}
This simple program simulation see only reduced after 1, not expected delay diminishing returns
At this time will question? Clearly see how such a simple procedure is right, don't move!
Now call LED as a test, the delay is a normal
Void main ()
{
While (1)
{
A -;
P1=P1 & lt; <1;
YS=54000; While (YS);
if(! (P1) P1=255;
}
}
After analysis should be a delay in the digital tube display affect the main function of the delay, in order to verify the inference, modify the code is as follows:
Void main ()
{
While (1)
{
A -;
P1=P1 & lt; <1;
YS=54; While (YS) ZhengShuXianShi (8, a);
if(! (P1) P1=255;
}
}
Is to ask a lot of similar problems, today just make this simple program for chestnut to answer such questions, by the way, some similar problems analysis ability is insufficient, unable to understand and solve when long, which is suspected other problems caused by the program can not run as expected.