|
发表于 2011-4-4 21:49:23
|
显示全部楼层
这个好说,回复【楼主位】Ian11122840 船儿舟
-----------------------------------------------------------------------
这个好说,你看程序里analog.c里面写得很清楚,没次调用ADC_Enable(),就会调用一次数据采集工作,使用中断时切换通道。
切换了0-17个通道,也就是18个。俯仰、滚转各四次(其他的自己看)。
每次ADC_Enable()之后很快会完成上述这个工作的,因为ADC很快,至少比2ms快多拉。
然后再最后一个状态,会关闭这种自动采集。
那什么时候再采集呢,你搜一下ADC_Enable()在哪里用了就知道啦,在Mean()里用了!Mean()在哪里用了?在MotorControl()里用了,还是第一个调用的程序呢!
那MotorControl()多长时间运行一次?
看这里:主函数中:
// begin of main loop
while (1)
{
if(UpdateMotor && ADReady) // control interval
{
UpdateMotor = 0; // reset Flag, is enabled every 2 ms by ISR of timer0
//J4HIGH;
MotorControl();
//J4LOW;
。。。。。。
所以,MotorControl()的调用频率受UpdateMotor、 ADReady两个控制变量控。
ADReady不管他,因为他很快就会结束。
UpdateMotor变量是受硬件的定时器控制,固定时间置一的。在这里:
timer0的中断服务程序:
ISR(TIMER0_OVF_vect) // 9.765 kHz
{
static uint8_t cnt_1ms = 1,cnt = 0;
uint8_t Beeper_On = 0;
#ifdef USE_NAVICTRL
if(SendSPI) SendSPI--; // if SendSPI is 0, the transmit of a byte via SPI bus to and from The Navicontrol is done
#endif
#ifdef USE_RC_SPEKTRUM
if(SpektrumTimer) SpektrumTimer--;
#endif
if(!cnt--) // every 10th run (9.765kHz/10 = 976Hz)
{
cnt = 9;
cnt_1ms++;
cnt_1ms %= 2;
if(!cnt_1ms) UpdateMotor = 1; // every 2nd run (976Hz/2 = 488 Hz)
CountMilliseconds++; // increment millisecond counter
}
。。。。。。。。。。。。
看到488Hz啦吧,呵呵,大约是2ms多一点啦~~ |
|