Go Down

Topic: Weird unexplainable behaviour (Read 361 times) previous topic - next topic

brucester83

Hi,

I have wrote a simple program that tests external interrupts.

tx is connected to the gate of a mosfet and pin2 is the input of a square wave that goes up and down twice on each loop.

Here is the code:

int tx = 12;     
volatile int x = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(tx, OUTPUT);
  attachInterrupt(0, increment, RISING);
}

void loop()
{
  digitalWrite(tx, HIGH);   
  delay(10);
  digitalWrite(tx, LOW);

  Serial.println(x, DEC);
  delay(1000);
}

void increment()
{
    x++;
}



When i dont turn my circuits battery on, the output is:

1
2
3
4
5
6
7.....

When it is on it is

1
345
346
600
623
689
1100...

Why am i getting such weirdness?

Surely when my external battery off and the external circut recieves no power, the input pin (2) should always be low and the output should be:
0
0
0
0
0
0

when it is on it should be
2
4
6
8
10...

I am totally confused by this.

Any tips or suggestions would be appreciated.

Thanks

dc42

It sounds to me that you don't have some grounds connected. Post a schematic.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

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