View Single Post
Old 05-25-2009, 09:33 PM   #1412 (permalink)
dcb
needs more cowbell
 
dcb's Avatar
 
Join Date: Feb 2008
Location: ÿ
Posts: 5,038

pimp mobile - '81 suzuki gs 250 t
90 day: 96.29 mpg (US)

schnitzel - '01 Volkswagen Golf TDI
90 day: 53.56 mpg (US)
Thanks: 158
Thanked 269 Times in 212 Posts
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

 
}

__________________
WINDMILLS DO NOT WORK THAT WAY!!!

Last edited by dcb; 05-26-2009 at 12:44 AM..
  Reply With Quote