Go Down

Topic: interrupt programming (Read 587 times) previous topic - next topic

cyborg8274

can someone write a program that can read the pulses and generate output to required pins ?


UKHeliBob

can someone write a program that can read the pulses and generate output to required pins ?
Yes.  You.

What exactly are you trying to do ?
Where does the input come from ?
What is the frequency of the input(s) ?
What exactly is the required output ?
What else, if anything, is the program doing ?
Why do you believe that you need to use interrupts rather than polling ?
What have you tried so far ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Danois90

Why not do it on your own?
Instead of mocking what's wrong, teach what's right! ;)
When you get help, remember to thank the helper and give some karma!
Please, do NOT send me any private messages!!

UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

cyborg8274

I'm trying to read pulses from coin acceptor (sensor) and depending on the pulses, different solenoids should work.

here, in the sensor I can program the sensor to give pulses as i want
for example for p1 coin i can set it to give 5 pulses and for p2 coin i can set it to give 10 pulses.
So I've programmed it to give
2 pulses for P1 coin                                          
5 pulses for p2 coin
10 pulses for p3 coin

now the sensor gives pulse output which should be read in the arduino and if 5 pulses are detected it should activate a solenoid and if 10 pulses are detected it should activate another solenoid. In this solenoid should push (high) and a delay then LOW should be given.

I don't have any idea what polling is, but i do know it should work on ISR as i've seen in some coin acceptor projects.

here, arduino should first detect all the pulses then activate the solenoid because if it accepts the pulses as they come it'll be a problem because when 5 pulses come arduino might directly jump into 2 pulses loop and activate different solenoid. please help

Danois90

Hire someone in the Gigs and Collaborations forum if you cannot realize your (apparently) commercial project your self :)
Instead of mocking what's wrong, teach what's right! ;)
When you get help, remember to thank the helper and give some karma!
Please, do NOT send me any private messages!!

cyborg8274

 FYI I'm a student and i'm making coin sorting machine. I ain't selling anything.

PaulS

Quote
here, arduino should first detect all the pulses
How is the Arduino supposed to know that there will be no more pulses, so that it knows it has detected ALL of them?

If you can define requirements that do NOT have gaping holes, like "detect all pulses", then you will have a MUCH easier time implementing the requirements in the code.
The art of getting good answers lies in asking good questions.

gfvalvo

FYI I'm a student and i'm making coin sorting machine. I ain't selling anything.
You mean you're looking for someone to do your assignment for you?

PaulMurrayCbr

How long are these pulses?

Let's assume that each pulse is about 100ms long and that there's a gap of 100ms between pulses. There should be a 20ms debounce, and when there has been 250ms without a pulse, then we can assume that the train of pulses is complete.

Code: [Select]

int pulseCount;
uint32_t mostRecentChange_ms;
byte pinRead;

void loop() {
  if(millis() - mostRecentChange_ms < 20) return; // debounce

  byte prevRead = pinRead;
  pinRead = digitalRead(the pin);
 
  if(prevRead != pinRead) mostRecentChange_ms = millis();

  if(pinRead == HIGH && prevRead == LOW) {
      pulseCount ++;
  }

  if(pinRead == LOW && millis() - mostRecentChange_ms >= 250 && pulseCount > 0) {
    switch(pulseCount) {
      case 2:
        activate the 2-pulse solenoid;
        break;
      case 5:
        activate the 5-pulse solenoid;
        break;
      case 10:
        activate the 10-pulse solenoid;
        break;
      default:
        activate the unrecognised coin solenoid;
        break;
    }

    pulseCount = 0;
  }
}


I always like doing people's homework for them. It cheapens the value of having a qualification. I don't have a degree, but I do have experience, so this works out well for me.
http://paulmurraycbr.github.io/ArduinoTheOOWay.html

Go Up