Interrupt problems *solved*


hi!

i'm having problems project includes interrupt routine. interrupt routine i'm generating 2 pwm-signals. problem i'm not quite sure how stop generating pwms.

code: [select]

isr(timer1_compa_vect) //interrupt rutine
{
   if(sample >= sinewave_length)
   {
       sample = -1;
   }
   
   else
   {
     if(togglesinewavea == high)
     {
          ocr0a = amplitudesinea * pgm_read_byte(&sinewave_data[sample]);
     }
     
     else if(togglesinewavea == low)
     {
         ocr0a = 0;
     }
     if(togglesinewaveb == high)
     {
       ocr0b = amplitudesineb * pgm_read_byte(&sinewave_data[sample]);
     }
   
     else if(togglesinewaveb == low)
     {
        ocr0b = 0;
     }
     
   }
   sample++;
}


inspired http://www.scribd.com/tranvandoanh/d/52034914-sine-wave-generator


this works ok, might not solution.. anyhow, timer set this:

code: [select]

 pinmode(6,output);
 pinmode(5,output);
 //settting fast pwm mode & b
 tccr0a |= _bv(wgm01);
 tccr0a |= _bv(wgm00);
 //?????????????
 tccr0b |= _bv(wgm00);
 tccr0b |= _bv(wgm01);

 //toggle on compare match
 tccr0a |=_bv(com0a1);
 tccr0a &= ~_bv(com0a0);
 tccr0a |=_bv(com0b1);
 tccr0a &= ~_bv(com0a0);

 //prescaler
 tccr0b = (tccr0b & ~(_bv(cs02) | _bv(cs01))) | _bv(cs00);

 ocr0a = pgm_read_byte(&sinewave_data[0]);
 ocr0b = pgm_read_byte(&sinewave_data[0]);
 cli();

 //setting pwm waveform generation mode
 tccr1b = (tccr1b & ~_bv(wgm13)) | _bv(wgm12);
 tccr1a = tccr1a & ~(_bv(wgm11) | _bv(wgm10));

 //pre-scaler
 tccr1b = (tccr1b & ~(_bv(cs12) | _bv(cs11))) | _bv(cs10);

 ocr1a = f_cpu / sample_rate; //
 ocr1b = f_cpu / sample_rate;

 timsk1 |= _bv(ocie1a);
 sample = 0;
 sei();


the pwms converted lp-filter 50 hz sinus signals, works excellent. setting togglesinewaveb, pwms can turned off, not sufficient in case..

the problems start when i'm trying execute other functions meanwhile having interrupt routine executed every once in while. atm i'm basicly having simple function execute before timers set , after i've set them.

code: [select]
void switchthatpin()
{
    digitalwrite(8,high);
    delay(500);
    digitalwrite(8,low);
    delay(1000);
    digitalwrite(8,high);
    delay(500);
    digitalwrite(8,low);
}



works pre init of timers, after not.. obviously. i've tried few methods, unfortunately without success.


so question is, how stop interrupt routine? i've tried cli(), not work.. tried:

code: [select]

  //clears waveforms
  tccr0a&=~_bv(wgm01);
  tccr0a&=~_bv(wgm02);
  tccr0a&=~_bv(wgm00);  
 
  //disconnect oc0a
  tccr0a&=~_bv(com0a1);
  tccr0a&=~_bv(com0a0);
 
  //disconnect oc0b
  tccr0a&=~_bv(com0b1);
  tccr0a&=~_bv(com0b0);
 
  //stops timer
  tccr0b &=~_bv(cs02);
  tccr0b &=~_bv(cs01);
  tccr0b &=~_bv(cs00);  
 
  timsk1 &=~_bv(ocie1a);
  timsk1 &=~_bv(ocie0b);
  //timsk1 &=~_bv(toie1);
  timsk1 &= ~(1<<toie1);



btw functions executed commands sent python..


any appreciated :)





i guess that:

code: [select]
tccrxa = 0;
tccrxb = 0;


would stop related timerx.



Arduino Forum > Using Arduino > Programming Questions > Interrupt problems *solved*


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial