Pages: [1]   Go Down
Author Topic: Arduino automatically triggers interrupt once while uploading  (Read 1273 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

I'm using an Arduino  Duemilanove with an Atmega328 on board. I'm using at as a controller for a electro-pneumatic gear shifter for a Formula Student car.

Two pushbuttons give inputs to the Arduino and after a software debounce delay, the state of the buttons is used to interrupt the microcontroller to either upshift or downshift depending on which button was pressed.

But every time I upload the program on the arduino, it triggers both the interrupts once even when the buttons are not pressed.
The interrupts are triggered only once and after that the program works smoothly.

I will post the code here soon.

Thanks
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i think the problem is every time you upload a program to arduinio  is a normal issue that interrupt come on
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I will post the code here soon.

The sooner, the better.  Without your code to see how the interrupts are setup, it will be difficult (or impossible) to help you.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

int upshiftbutton=5;
int downshiftbutton=4;
int sensorpin1=A0;
int sensorpin2=A2;
int sensorpin3=A1;
int upshiftcoil=10;
int downshiftcoil=8;
int sensorvalue1;
int sensorvalue2;
int sensorvalue3;
int upshiftint=7;
int downshiftint=6;
volatile int gearcounter=3;
int buttonState1;           
int lastButtonState1 = LOW;   
int buttonState2;             
int lastButtonState2 = LOW;   
long lastDebounceTime1 = 0;
long lastDebounceTime2 = 0;
long debounceDelay = 50;

void setup()
{
  Serial.begin(9600);
  pinMode(upshiftbutton,INPUT);
  pinMode(downshiftbutton,INPUT);
  pinMode(upshiftcoil,OUTPUT);
  pinMode(downshiftcoil,OUTPUT);
  pinMode(upshiftint,OUTPUT);
  pinMode(downshiftint,OUTPUT);
  pinMode(sensorpin1,INPUT);
  pinMode(sensorpin2,INPUT);
  pinMode(sensorpin3,INPUT);
  attachInterrupt(0,UPSHIFT,RISING);
  attachInterrupt(1,DOWNSHIFT,RISING);
 }

void loop()
{   
 
 sensorvalue2=digitalRead(sensorpin2);
  if(sensorvalue2==1)
     {
      digitalWrite(upshiftcoil,LOW);
     }
     
 sensorvalue3=digitalRead(sensorpin3);
  if(sensorvalue3==1)
       {
         digitalWrite(downshiftcoil,LOW);
       }
     
 int reading1 = digitalRead(upshiftbutton);    \\debounce delay code
   if (reading1!= lastButtonState1)
    {
     lastDebounceTime1 = millis();
    }
 
  if ((millis() - lastDebounceTime1) > debounceDelay)
    {
     buttonState1 = reading1;
    }
 
 digitalWrite(upshiftint, buttonState1);
 lastButtonState1 = reading1;
 
 int reading2 = digitalRead(downshiftbutton);  \\debounce code

  if (reading2!= lastButtonState2)
    {
     lastDebounceTime2 = millis();
    }
 
  if ((millis() - lastDebounceTime2) > debounceDelay)
    {
     buttonState2 = reading2;
    }
 
 digitalWrite(downshiftint, buttonState2);
 lastButtonState2 = reading2;
}

void UPSHIFT ()

{
  int up=digitalRead(5);
  if(up==1)
  {
    sensorvalue1=digitalRead(sensorpin1);
        if  (sensorvalue1==1 && gearcounter<6)
            {
              gearcounter++;
              Serial.println(gearcounter);
             digitalWrite(upshiftcoil,HIGH);
             Serial.println("UPSHIFT");
            }
  }
}

void DOWNSHIFT ()
{
  int down=digitalRead(4);
  if(down==1)
    {   
     sensorvalue1=digitalRead(sensorpin1);
        if  (sensorvalue1==1 && gearcounter>1)
            {
              gearcounter--;
              Serial.println(gearcounter);
             digitalWrite(downshiftcoil,HIGH);
            Serial.println("DOWNSHIFT");
            }
    }
}


Right now I got rid of the unneeded interrupts by only letting the interrupt function do anything when the pushbuttons are pressed, when the Arduino is getting uploaded, no button is pressed hence it ignores the interrupt.
But is there any better way of doing this?
Logged

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6146
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

When unpressed are your buttons using pull-down resistors (or pull-up?) to prevent them from floating?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Pull down resistors are being used, hence when button is pressed, Arduino reads high.

Nishad
Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 207
Posts: 12903
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
int upshiftbutton=5;
int downshiftbutton=4;

http://www.arduino.cc/en/Hacking/PinMapping168

...locate the pins labeled "INT0" and "INT1".  The red labels are?
Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, you might consider another approach for a gear indicator.  Right now if your arduino freezes your "formula" car will stop shifting, as well as your formula car has to be in a certain position when the arduino is powered up.

If you can monitor engine rpm and vehicle speed, you could pre-determine the ratios for the different gears and display the gear number that most closely matches the existing rpm-mph ratio.  As well you would be on your way to having some digital instrumentation.

I'm guessing you are using a motorcycle transmission?  Does it have a neutral switch?  Does this shifter skip neutral?

I should note that it doesn't take long for a driver to get the hang of selecting the right gear without any visual feedback.  I would not add an arduino to the critical path solely for a gear position indicator, one glitch and you lose the race.  If you want button shifts, them implement them as buttons without an arduino, them maybe monitor the same buttons from arduino to indicate the current gear.
« Last Edit: June 06, 2011, 08:17:00 am by dcb » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 8
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey

Ya the shifter does skip neutral as it is a motorcycle transmission. But the clutch has a manual override which can be used to stop the car.
I have also written a program to monitor the ratio between the engine rpm and the wheel speed but haven't tested it on the car yet.  Car is getting its bodywork done. Meanwhile im testing this shifter on the old engine we have in the workshop.

The arduino is only being used for the gear shifter so no other code is gonna affect it. The shifting code itself has worked pretty reliably uptil now.

Thanks

Nishad
Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

manual override?  Don't feed me bullcrap when I'm trying to be helpful.  As you already have one glitch while uploading, don't be surprised if you find another at some point, i.e. during competition.  You don't have to listen to my free advice, but when you decide to write code that controls a vehicle, you better damn well know what you are doing.  The best failure scenario is you have to explain why the gear indicator cost the team the race, the worst scenario is it decides on its own to downshift to 1st at 120mph in a corner.  Remember, there is going to be a human in this thing and others on the track, there is no room for the programmers ego.

Manual override?  What exactly is being overridden (and why do you have that mentality)?
« Last Edit: June 07, 2011, 06:57:13 am by dcb » Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this it?  looks like a real fun project though.  Please do refrain from adding unnecessary complications and dependencies (and points of failure) though, please.


http://www.bellevision.com/index.php?action=topnews&type=1107
Logged

Pages: [1]   Go Up
Jump to: