Loading...
  Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 24, 2013, 09:58:26 am
Quote
You don't need to initialise it at all - it is static, so the compiler makes it zero, unless you tell it otherwise.
But you do need to update it.

Code:
static unsigned long lastTick = 0;
So something more like
Code:
static unsigned long lastTick = millis();
2  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 24, 2013, 09:34:46 am
Is there a way to stay in the loop without using delay I do want to be able to service sensors while counting out the stir time?
3  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 24, 2013, 09:28:29 am
Quote
bigger hint:



 
Code:
if (millis() - 0 >= 1000)

I am confused by this code. I have it working elsewhere. It counts 1000 millisec and increments the second variable.
But, I think I am tracking that  millis() returns a rather large number (elapsed time) and - 0 it is still >= 1000.
So I need to initialize
Code:
static unsigned long lastTick = 0;
this differently?
4  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 23, 2013, 03:43:39 pm
Quote
It's an understandable side-effect of cross-posting.
Actually I posted a new question because I was receiving critique instead of help. Seems there is no shortage of people to tell you you are doing it wrong, and only a few pathfinders.
5  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 23, 2013, 03:23:44 pm

Quote
What does it do? What would you like it to do? What serial output do you get?

Since you're calling it in loop, I assume you're expecting it to spool up for a 10 second stir and then wind down and stop and then do it all again repeatedly. If that's the case but it only works once, the likely cause is that you never set you second variable back to zero. After the wind down would be a good place.

for this example that is exactly what i want it to do

This is what it is doing.
motorspeed = 176
motorspeed = 177
motorspeed = 178
motorspeed = 179
motorspeed = MAX 25
Brake On motorspeed = 0
motorspeed = 1
motorspeed = 2
motorspeed = 3
motorspeed = 4
motorspeed = 5
motorspeed = 6
 It never reaches the timer or the ramp down.






Quote
Every time the stir() function is called the stir speed will return to zero then ramp up.  Is that what you want ?  Do you want the program to stay in the stir() function for 10 seconds or for it to check each time that it is called whether it should ramp up the speed or whether it is time to ramp down the stir speed if it is running at full speed and has been for 10 seconds ?
I want to call the stir() function passing a duration in seconds ..ramp up count to the variable passed ... then ramp down and then exit the function. I want to stay in the function until the ramp down is complete.
6  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 23, 2013, 03:02:49 pm
Yup, Still wrestling with this issue. I seem to get comments and criticisms instead of help.
7  Using Arduino / Programming Questions / Re: Not Enough Analog Out pins on: April 23, 2013, 02:43:10 pm
But this is a small issue on the butt of a larger problem.

Motor Acceleration Timer Deceleration Problem
http://arduino.cc/forum/index.php/topic,162373.msg1213468.html#msg1213468
8  Using Arduino / Programming Questions / Re: Not Enough Analog Out pins on: April 23, 2013, 02:40:13 pm
Exactly. I read somewhere about Pseudo pwm on a digital pin but I dont know.
9  Using Arduino / Programming Questions / Re: Motor Acceleration Timer Deceleration Problem on: April 23, 2013, 02:38:19 pm
Quote
Instead, it?


motorspeed = 176
motorspeed = 177
motorspeed = 178
motorspeed = 179
motorspeed = MAX 25
Brake On motorspeed = 0
motorspeed = 1
motorspeed = 2
motorspeed = 3
motorspeed = 4
motorspeed = 5
motorspeed = 6

Quote
I fail to see the purpose of using millis() to create a non-blocking function and then using delay() in the same function.

The millis keeps track of time and the delay smooths out the accel/decel ramps
10  Using Arduino / Programming Questions / Re: Not Enough Analog Out pins on: April 23, 2013, 02:19:53 pm
I only have 3 analog outputs left but a lot of digital pins.
11  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 23, 2013, 12:50:10 pm
OK, I am looking at using a function to spool up and spool down the motors and handle the duration timer. Here is what I have that does not work. Please Help!
Code:
//////////////////////////////

#define STIRRING1_TIME 20  //   1200
#define Srelay    51
int stir_speed = 180;
int time = 0; 
int pump_pwm_del = 1;
int second = 0;
void setup() {
  Serial.begin(57600);
  Serial.println("setup");

  digitalWrite(23,HIGH);
 
  /////////////////////////////
  pinMode(Srelay, OUTPUT); // Provides/Removes Power to motor controllers
  pinMode(44, OUTPUT); //Shared PWM Signal to all 4 motor controllers
  pinMode(23, OUTPUT);   //Stir motor
  digitalWrite(Srelay,LOW);//Turn off power to motor controllers
}

void loop() {
  digitalWrite(Srelay,HIGH);//Turn off power to motor controllers   
  Serial.println("23");
  stir(10);
 
}

/////////////////////////////////////////////////////////
//Stir
int stir(int time){
  digitalWrite(23,LOW); // Release Brake Stir Motor
     Serial.print("Brake On ");
  for (int motorspeed = 0; motorspeed < stir_speed; motorspeed++) {
    analogWrite(44, motorspeed);// Ramp up speed
     Serial.print("motorspeed = ");
    Serial.println(motorspeed);
    delay(4);
  }
  //motor at speed start counting
  Serial.print("motorspeed = MAX ");
  static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
  // (static variables are initialized once and keep their values between function calls)
  if (millis() - lastTick >= 1000) {
   
    lastTick = millis();
    second++;
   
   
    Serial.print("Second = ");
    Serial.println(second);

   
    if (second > time){   // Count over decel motor
      Serial.print("Time Out");
       for (int motorspeed = stir_speed; motorspeed >= 0; motorspeed--) {
    analogWrite(44, motorspeed);  //Ramp down
     Serial.print("motorspeed = ");
    Serial.println(motorspeed);
    delay(4);
  }
    Serial.print("motorspeed = MIN ");
  digitalWrite(23, HIGH);// Set Brake stir Motor
   Serial.print("Brake On ");
    }
  }
 
  delay(1000);
}
12  Using Arduino / Programming Questions / Not Enough Analog Out pins on: April 23, 2013, 12:46:29 pm
I am using the adafruit 2.8 TFT display and it uses all of the analog pins except 42, 44 and 46 so I am using one pin(44) for all four of the motor controllers. I would really like each to have its own signal. Can this be done some other way?
13  Using Arduino / Programming Questions / Motor Acceleration Timer Deceleration Problem on: April 23, 2013, 12:32:27 pm
I am having some trouble getting the following code to work. Any Ideas?

Code:
//////////////////////////////

#define STIRRING1_TIME 20  //   1200
#define Srelay    51
int stir_speed = 180;
int time = 0;  
int pump_pwm_del = 1;
int second = 0;
void setup() {
  Serial.begin(57600);
  Serial.println("setup");

  digitalWrite(23,HIGH);
  
  /////////////////////////////
  pinMode(Srelay, OUTPUT); // Provides/Removes Power to motor controllers
  pinMode(44, OUTPUT); //Shared PWM Signal to all 4 motor controllers
  pinMode(23, OUTPUT);   //Stir motor
  digitalWrite(Srelay,LOW);//Turn off power to motor controllers
}

void loop() {
  digitalWrite(Srelay,HIGH);//Turn off power to motor controllers  
  Serial.println("23");
  stir(10);
 
}

/////////////////////////////////////////////////////////
//Stir
int stir(int time){
  digitalWrite(23,LOW); // Release Brake Stir Motor
     Serial.print("Brake On ");
  for (int motorspeed = 0; motorspeed < stir_speed; motorspeed++) {
    analogWrite(44, motorspeed);// Ramp up speed
     Serial.print("motorspeed = ");
    Serial.println(motorspeed);
    delay(4);
  }
  //motor at speed start counting
  Serial.print("motorspeed = MAX ");
  static unsigned long lastTick = 0; // set up a local variable to hold the last time we moved forward one second
  // (static variables are initialized once and keep their values between function calls)
  if (millis() - lastTick >= 1000) {
    
    lastTick = millis();
    second++;
  
    
    Serial.print("Second = ");
    Serial.println(second);

  
    if (second > time){   // Count over decel motor
      Serial.print("Time Out");
       for (int motorspeed = stir_speed; motorspeed >= 0; motorspeed--) {
    analogWrite(44, motorspeed);  //Ramp down
     Serial.print("motorspeed = ");
    Serial.println(motorspeed);
    delay(4);
  }
    Serial.print("motorspeed = MIN ");
  digitalWrite(23, HIGH);// Set Brake stir Motor
   Serial.print("Brake On ");
    }
  }
 
  delay(1000);
}

It is supposed to Ramp up and  do the timer code and then ramp down.

motorspeed = 176
motorspeed = 177
motorspeed = 178
motorspeed = 179
motorspeed = MAX 25
Brake On motorspeed = 0
motorspeed = 1
motorspeed = 2
motorspeed = 3
motorspeed = 4
motorspeed = 5
motorspeed = 6

14  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 17, 2013, 09:38:06 am
This sounds good for rev 2. It will take a lot of consideration. And yeah the original plan called for 12 states but it evolved. There are redundant states that could have values passed to a single state, but you know how it is, "Its working move on to the next phase" pressure.Still I am only using 20 % of the mega's program space. Do you have any simple FSM code that you are willing to share. I found the example for the remote car starter and learned a lot from that. Bad habits included. I would be done by now but I had to upgrade the motor controls from relays to an H-Bridge.
15  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 09:16:03 pm
Code:
if (motorspeedA >= stirspeed){ //?? reached desired speed?
// next step
// Rest of your program
//
}
else {
   motorspeedA++;
   analogWrite(44, motorspeedA);
   delay(stir_ramp);
}

I can wrap my head around this.


Quote
As far as I can see, you're using the global counter variable as a sub-state which controls actions within the current state. It's not the most elegant FSM design I've ever seen but it seems viable, and with that scheme in place it seems appropriate to use that to handle startup processing for this state. I don't see that this is any less elegant than the one-off display output.
LOL. I am sure it is not the most elegant ever it is the only one I have ever written and example code was hard to come by. I really did not like what I came up with for the display but it worked so I moved on.

 
Code:
Just out of curiosity, are any of the other states similar to this one? I noticed that several identifiers associated with this state contain a number, which always makes me suspicious.
Yes there is 3 of every thing (fill, stir and drain).  Suspicious of what?


Quote
The mixed use of of blocking and non-blocking code, widespread use of global data (which now requires duplicate handling for each state) and sheer number of states would make me want to rationalise the state machine.
Post
And, you lost me. I will look into rationalising.

This is the Prototype and there is another version coming so I am really trying to wrap this up for the beta testers. So right now function is more important than style.
Pages: [1] 2 3 4