Hope I'm not intruding, but here is an outline of how I might handle interrupts (just using bytes for example)
PHP Code:
volatile byte current //most important
volatile byte throttle
volatile byte temperature
volatile adcMode=9;// (9 = ready, 0 = throttle, 1 = temperature, 2 = current)
ISR timer1(){//16khz timer isr
static byte distributor=0; //unsigned
if(adcMode==9){//wait for last adc request to finish
distributor++;
adcMode=2;//default to current read
if(distributor==128)
adcMode=1;//read temperature once out of every 255 calls (~ 60hz)
else if(distributor==0)
adcMode=0;//read throttle once out of every 255 calls (~ 60hz)
ADMUX &= (128+64+32+16);
ADMUX +=adcMode; //select channel
ADCSRA |= 64;//start adc conversion
}
}
ISR adcComplete(){
if(adcMode==0)
throttle=ADC
else if(adcMode==1)
temperature=ADC
else
current=ADC
adcMode=9;//signify that we are ready for another reading
}
main(){
init()
while(true){
cli
byte tmpTemp=temperature
byte tmpCurrent=current
byte tmpThrottle=throttle
sei
do interesting things to the pwm or whatever based on tmp variables here
}
}