我目前正在努力重建四轮直升机控制器。
我正在研究从我的陀螺仪传感器获取数据,为此,我正在使用 带有中断的ISR。
我的问题是,当我在主程序上调用我的函数“gyro.getX”时,它可以工作。 但是,当我从ISR调用此函数时,它不起作用。 我发现错误的共鸣,我正在使用的功能由“Adafruit_LSM9DS0”库(来自ST)提供,它使用了“时间戳”。 我的ISR的当前时间与我的主程序的当前时间不同,但我不知道该怎么做。
这是我程序的快捷方式:
void loop(){
/*main prog*/
}
/*
*Reserve interrupt routine service (ISR) by Arduino
*/
ISR(TIMER2_OVF_vect)
{
TCNT2 = 256 - 250; // 250 x 16 µS = 4 ms
if (varCompteur++ > 25)// 25 * 4 ms = 100 ms (half-period)
{
varCompteur = 0;
SensorGet(pX, pY);//Feed gyro circular buffers
}
}
void SensorGet(float * pRollX, float * pPitchY)
{
lsm.getEvent(&accel, &mag, &gyro, &temp);
GiroX_Feed(pX, gyro.gyro.x);
GiroY_Feed(pPitchY, gyro.gyro.y);
}
bool Adafruit_LSM9DS0::getEvent(sensors_event_t *accelEvent,
sensors_event_t *magEvent,
sensors_event_t *gyroEvent,
sensors_event_t *tempEvent)
{
/* Grab new sensor reading and timestamp. */
read();
uint32_t timestamp = millis();
/* Update appropriate sensor events. */
if (accelEvent) getAccelEvent(accelEvent, timestamp);
if (magEvent) getMagEvent(magEvent, timestamp);
if (gyroEvent) getGyroEvent(gyroEvent, timestamp);
if (tempEvent) getTempEvent(tempEvent, timestamp);
return true;
}
答案 0 :(得分:1)
问题不在于时间。问题可能是您的传感器使用I2C并且在中断例程期间被禁用,或者它的某些其他通信协议依赖于中断来运行,因此在您的ISR期间被禁用。
你真的在滥用中断。这不是中断的目的。中断应该超级快,没有时间进行通信。所以真正的问题是为什么你认为你需要一个中断?