Pages: [1]   Go Down
Author Topic: Shiftlight  (Read 470 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to make a shift light.

Code...
Code:
volatile unsigned long now,lastcount=0;
volatile int count;
volatile int interval;
int x=0;
void setup() {               
  Serial.begin(115200);
  attachInterrupt(0, tachcount, RISING); 
}

void loop()
{
  if(interval!=x)
Serial.println(interval);
else
x=interval;
}

void tachcount()
{
  if(count<9)
  {count++;}
  else
  {
now = millis();
interval=now-lastcount;
lastcount=now;
count=0;
  }
}


Input is a 12V square wave pulse from the ignition, fed to a voltage divider (1:1) with a 5.1V Zener to the ground.

I put a scope to then incoming pulse, the width is 300 uS at approximately 11.2 V

I haven't seen the waveform after the voltage divider and the zener, will do tomorrow.

The issue is that the interval between 2 pulses is not the kind of value I am expecting, with 1 pulse every rotation of the engine (2 stroke) at about 1200 rpm it should be about 50 ms. I get way lower values than that on the serial port.

Now my question is that is the pulse width of 300 uS too small to provide a clean trigger signal for the arduino? Also would a 4n33 opto coupler be able to generate a clean enough pulse for the arduino with the 300 uS input?

Does the Zener change the characterstics of a square wave pulse?

Any other inputs anyone has would be appreciated.
Logged

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


Ignoring the other bugs in your Sketch, I'll focus on the one that will cause you the most trouble.  Change loop to this...

Code:
void loop()
{
  if(interval!=x)
  {
    Serial.println(interval);
    x=interval;
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Will fix that, stoopid mistake on my part.

The code that I actually had used for testing didnt even have that condition, it dumped to the serial port no matter what, causing overload of data, so wanted to avoid that to make troubleshooting easier.

--Tj
Logged

0
Offline Offline
Edison Member
*
Karma: 16
Posts: 1579
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I did something similar some time ago.... http://real2electronics.blogspot.com/2009/09/shift-lights-con-arduino.html
It´s in Spanish, but that it´s not important for the code smiley-wink
You can also use the google translator.

The video was using a phone (bad quality):


I hope it helps.


Regards,


Igor



« Last Edit: March 19, 2011, 07:00:16 am by Igor R » Logged


Pages: [1]   Go Up
Jump to: