Go Down

Topic: Time Interrupts (Read 461 times) previous topic - next topic

fayadAli

I need help with setting a time interrupt. I found the attach interrupt function but I don't know how to time control it. Is there another functions that triggers the interrupt every constant amount of time. I know that in HCS12 dragon board there is one. I want the other objects to run at the same time I am charging the compressor. All the code is ready but I dont know how to set the interrupt to be timed.

here is how I need my code to look like.

start the compressor
set the actuator.
set the servo
set the second actuator.
interrupt { if (the amount of pressure in the chamber has reached the threshold )
              stop the compressor.
              shoot the ball
              set the servo and actuators back to their position}

Msquare

The code you outline does not need an interrupt - you can simply wait until the threshold is reached.

Is there some "timeout" that is not included in your outline? That, too, can be done without interrupts, by checking time (millis) while you are waiting for the threshold.

Otherwise - a more detailed outline

Delta_G

The attachInterrupt function works with the pin change interrupts.  Those cause an interrupt whenever a certain condition is found on a certain pin.

What you want is timer interrupts.  Check out the Timer1 library.

fayadAli

Thats the whole code but instead writing turn pins high and low I am writing the algorithm. How do I make the compressor and the other parts run at the same time? I dont want the other parts to sit still while the compressor is charging.
how to make it without an interrupt.
Do u mean this way MSquare
Code: [Select]

turn on compressor
turn on actuator in the first direction
while (compressor < 400 || actuator < value)
{

load the ball;
if (compressor > 400)
{
turn off compressor
}
set servo to a specific angle.
if(actuator > itsDesiredValue)
turn off the actuator

}
shoot the ball.
set servo back.
set actuator back.
[\code]

shelleycat

You don't need interrupts for this (unless your compressor or actuator has to be driven on or off in under a millisecond).

How about something like this, with some variables to keep track of the current states of the system.  Remember its all being run in a loop, so everything you write should do its stuff then return to the main loop quickly.

I don't know what your system is, but seems the compressor and actuator are actually separate subsystems.

Code: [Select]

boolean pressure_OK;
boolean positioned_OK;

loop()
{

//compressor
if (pressure < 400)
{
  start_compressor();
  pressure_OK = false;
}
else
{
  stop_compressor();
  pressure_OK = true;
}


// actuator
measured_angle = measure_the_angle();
if (measured_angle != desired_angle)
{
  move_actuator();
  positioned_OK = false;
}
else
{
  stop_actuator();
  positioned_OK = true;
}

// firing
if (pressure_OK && positioned_OK)
{
  trigger_output();
 
}

} // end loop


Go Up