Pages: [1]   Go Down
Author Topic: resettable counter  (Read 9012 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to use an Arduino Uno for enabling/disabling a diesel injector. The idea is to have 2 inputs, and 1 output. Input one is to enable the diesel injector, by a manual start button (one shot). Input two is for receiving TTL pulses which represent the number of injections are done. The output should function as interruption. This contact should close (become high) upon pushing the start button. It should open in case there is no power applied, or when the number of programmed pulses on input two is reached. TTL pulses are like 1msec wide, at dutycle 50%.

Because I want to be able to change the number of injections allowed easily, I want to start using this programmable device. playing with my device, trying different numbers for the example "Button State Change" , I think this should be possible. When looking at this program example, it looks logical to me, but  I have no experience in programm languages. Therefore I am wondering how to insert an extra input which will allow the device to start (reset)again after a cyclus.

Is there already a programm available for this, or can anyone give me some direction in starting developing?

Thanks in advance, regards, Theo
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8497
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Do I understand correctly.

IP1 goes active, start injecting and count injection pulses on IP2.
After N pulses stop injecting.
If power fails stop injecting.

Is that the guts of the matter?

______
Rob



Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

Hello Rob,

When IP1 receives a one shot pulse from a manual push button, output 13 is supposed to go high (LED on). This high state will be used to drive a relais. This relais is used to enable/disable an injector. so, the injector can now receive current pulses. the number of applied current pulses will be counted by IP2.

So, the arduino only counts, and will disable its output, when programmed count is reached. But it does not produce the pulses. It only needs to count, and reset.


Is this clear to you? Is this difficult to programm?


Thanks, Regards, Theo

Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8497
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here's a code snippet to get you started.

Code:
#define IP1 2  // use your pin numbers here
#define IP2 3
#define RELAY 13
#define N_PULSES 40

void setup () {

  pinMode (IP1, INPUT);
  pinMode (IP2, INPUT);
  pinMode (RELAY, OUTPUT);
  
  digitalWrite (RELAY, LOW);
  
}

void loop () {
  // wait for button to be pressed
  // NOTE: input doesn't really need to be debounced
  //       assumes pull down resistor on switch
  while (digitalRead(IP1) != HIGH) {};
  
  // relay activated
  digitalWrite (RELAY, HIGH);
  
  for (int i = 0; i < N_PULSES; i++) {
    // just use pulseIn() to count the pulses
    // don't care about the pulse width
    pulseIn (IP2, HIGH);
  }
  
  // relay deactivated
  digitalWrite (RELAY, LOW);
 
  // assumes the one-shot on IP1 is set to < the time N_PULSES takes
  // if not then wait here for IP1 to go LOW again ie. button released
 
}

As you said a monostable on the button I'm assuming a short debounced pulse on IP1.

If it's really just a pushbutton the release of the buttton will have to be debounced.

Hope that will allow you to have a crack at it.

______
Rob
« Last Edit: January 23, 2011, 10:02:09 am by graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

Hello Rob,


After modificating the program like showed, it works. Only the number which entered, does not correspond to number which will be counted. When entering 12, counter will count 3, when enter 40, counter counts up to 7, and when I enter 100, it will count to 20. I am thinking about wheter this is binair, but this doesn't correspond. Can you help me how to solve this?

Until now I am already very happy with my results


Thanks!! Theo
Logged

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

My Code:


Code:
//Constants which won't change:
const int IP1 = 2;  // use your pin numbers here: This is my start button
const int IP2 = 3;  // This is my counter input
const int RELAY = 13;  // This is my injector enable output

// Variables will change:
int N_PULSES = 100; // This are number of injections allowed

void setup () {

  pinMode (IP1, INPUT);
  pinMode (IP2, INPUT);
  pinMode (RELAY, OUTPUT);
  
  digitalWrite (RELAY, LOW);
  
}

void loop () {
  // wait for button to be pressed
  // NOTE: input doesn't really need to be debounced
  //       assumes pull down resistor on switch
  while (digitalRead(IP1) != HIGH) {};
  
  // relay activated
  digitalWrite (RELAY, HIGH);
  
  for (int i = 0; i < N_PULSES; i++) {
    // just use pulseIn() to count the pulses
    // don't care about the pulse width
    pulseIn (IP2, HIGH);
  }
  
  // relay deactivated
  digitalWrite (RELAY, LOW);

  // assumes the one-shot on IP1 is set to < the time N_PULSES takes
  // if not then wait here for IP1 to go LOW again ie. button released
  
  
  //FOR THIS SETUP, AFTER 20 COUNTS OUTPUT 13 IS RESET, IS THIS BINAIR CODED?
  

}



Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8497
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What exactly is generating the "one shot" pulse on IP1?

______
Rob

Logged

Rob Gray aka the GRAYnomad www.robgray.com

Pages: [1]   Go Up
Jump to: