Go Down

Topic: Pulse generation using atmega 328 on arduino uno board. (Read 995 times) previous topic - next topic

akshay3207

I am trying to generate 6 firing pulses for firing SCR in AC to DC conversion. Following is the code used for the purpose.
As soon as the interrupt is set, pins 13 and 5 go  HIGH and then LOW, continuously for a period of 5ms giving a train of pulses.After 5ms they completely go LOW Thereafter exactly after 10ms from the point when the above two pins started to give pulses, pins 6 and 7 generate train of pulses for 5 min and for next 5 mins they are completely OFF.

But as soon as I start execution after the interrupt is generated, pulses are obtained from the 13 and 6 pins. but after a delay its been observed we are receiving the pulses for some time , but then there occurs a patch of time(almost 2 seconds) where none of these pulses are obtained from the micro controller.




int pin = 13;
volatile int state = 0;
int i;



void setup() {
      pinMode(pin, OUTPUT);
      pinMode(5, OUTPUT);
      pinMode(6, OUTPUT);
      pinMode(7, OUTPUT);
      attachInterrupt(0, Comparator, RISING);
}

void loop() {
               
                if(state==1){
                         
                         
                         for(i=0; i<=2 ; i++){
                           digitalWrite(pin, HIGH);
                           digitalWrite(5, HIGH);
                           delayMicroseconds(1000);
                           digitalWrite(pin, LOW);
                           digitalWrite(5, LOW);
                           delayMicroseconds(1000);
                         }
                         delayMicroseconds(4114);
                         for(i=0; i<=2 ; i++){
                           digitalWrite(6, HIGH);
                           digitalWrite(7, HIGH);
                           delayMicroseconds(1000);
                           digitalWrite(6, LOW);
                           digitalWrite(7, LOW);
                           delayMicroseconds(1000);
                         }
                         delayMicroseconds(3668);
                         
                     
                                 
                      }
                                             
                         
                 
                  }

void Comparator(){
                 state=1;
                 detachInterrupt(0);
                  }

johnwasser

#1
Apr 16, 2014, 12:41 am Last Edit: Apr 16, 2014, 12:44 am by johnwasser Reason: 1
Don't forget to add code tags by selecting your code an clicking on the '#' icon above the text box.

Of course your blinking repeats...  Nothing turns off "state=1" so every time through loop() it repeats the pattern.

Code: [Select]

const int pin = 13;
volatile int state = 0;
int i;

void setup() {
  pinMode(pin, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  attachInterrupt(0, Comparator, RISING);
}

void loop() {
  if(state==1) {
    for(i=0; i<=2 ; i++) {
      digitalWrite(pin, HIGH);
      digitalWrite(5, HIGH);
      delayMicroseconds(1000);
      digitalWrite(pin, LOW);
      digitalWrite(5, LOW);
      delayMicroseconds(1000);
    }

    delayMicroseconds(4114);

    for(i=0; i<=2 ; i++){
      digitalWrite(6, HIGH);
      digitalWrite(7, HIGH);
      delayMicroseconds(1000);
      digitalWrite(6, LOW);
      digitalWrite(7, LOW);
      delayMicroseconds(1000);
    }

    delayMicroseconds(3668);
  }
}

void Comparator() {
  state=1;
  detachInterrupt(0);
}

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy