Show Posts
Pages: 1 [2] 3 4 5
16  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.
17  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
18  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.
19  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);
}
20  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?
21  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

22  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.
23  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.
24  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 06:00:38 pm
Quote
is the function supposed to do whole cycle of pump during one call (it means ramp-up, run max speed until FILLING_TIME and then ramp-down) and then exit?
Yes exactly.

Being self-taught I did not have this verbage.
Quote
The implementation has blocking code to ramp the speed up and down but does not have any blocking code to wait for the elapsed time to pass.
This is the problem.

Quote
It also has a couple of global/static variables that it is incrementing and using to trigger display output.
Actually it inhibits repainting the screen and causing a flicker.

Quote
The only way that makes sense is for HandleFILLING1State() to be called repeatedly, so I assume that's what is happening.
Correct. The main loop is just a big switch case tree (correct verbage?) that sends the program to the proper Function continuously until the conditions dictate a state change.

Quote
the logic to turn the motor on and ramp the speed up should only be called on entry to the state. I would guess that corresponds to (counter == 1).
Correct. And the ramp down is the last thing to do other than resetting the variables.

Quote
You could add an if(counter==1){} statement and move the digital writes and acceleration ramp inside it.
This was the best I could come up with but it seemed inelegant.

Quote
My suggestion, for what it's worth, is that you break this state and this function up into three separates states corresponding to the accelerating, constant speed and decelerating phases. Each state could then be implemented with a trivial non-blocking piece of code and the use of global data would almost disappear.

This Would be better but I have 29 states right now so I would have to break up and render 21 of them up to do so.

Quote
Given that the FILLING1_TIME is defined separately from the pump acceleration characteristics, I wonder whether it's conceivable that the timeout could occur before the acceleration had completed, and what you would want to happen in that case.
If I understand what you are asking-
I am ramping up to max speed on the pumps then  running for 10 minutes and then ramping down to fill . The stirrer ramps up to a preset speed runs for 10 minutes and then ramps down and then reversing the pump for drain. I want to Start the timer after the motor reaches speed and then decel after counter time-out.
25  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 01:57:12 pm
Here is the stand alone PWM program this works but when I add it to the program I have the above problem. Maybe there is another approach.

Code:
////////////////////////////////////
int stir_speed = 80;
int stir_ramp = 20;
int pump_speed = 250;
int pump_ramp = 4;
////////////////////////////////////


#define stir_brake 25
#define pump1_brake 27
#define pump2_brake 29
#define pump3_brake 31
#define pump1_direction 33
#define pump2_direction 35
#define pump3_direction 37
void setup() {

  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    HIGH);
  digitalWrite(pump2_direction,HIGH);
  digitalWrite(pump2_brake,    HIGH);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    HIGH);
  
  
  
    pinMode(42,              OUTPUT); //Analog pin
    pinMode(44,              OUTPUT); //PWM Output common to all motor drivers
    pinMode(46,              OUTPUT); //Analog pin
    pinMode(stir_brake,      OUTPUT);
    pinMode(pump1_brake,     OUTPUT);
    pinMode(pump1_direction, OUTPUT);
    pinMode(pump2_brake,     OUTPUT);
    pinMode(pump2_direction, OUTPUT);
    pinMode(pump3_brake,     OUTPUT);    
    pinMode(pump3_direction, OUTPUT);
 
 
 int motorspeed = 0;
}

void loop() {
  
 
  digitalWrite(stir_brake,     LOW);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    HIGH);
  digitalWrite(pump2_direction,HIGH);
  digitalWrite(pump2_brake,    HIGH);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    HIGH);
  
  
  
    for ( int motorspeed ; motorspeed < stir_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(stir_ramp);
    }
    
     delay(2000);
    
    for (int motorspeed = stir_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(stir_ramp);
    }
  
    delay(20);  
  /////////////////////
  
  
  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    LOW);
  digitalWrite(pump2_direction,HIGH);
  digitalWrite(pump2_brake,    HIGH);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    HIGH);
  

  
    for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    
     delay(2000);
    
    for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    // pause between LEDs:
    delay(20);  
  

  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    LOW);
  digitalWrite(pump2_direction,LOW);
  digitalWrite(pump2_brake,    HIGH);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    HIGH);
  // iterate over the pins:
  
    for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    
     delay(2000);
  
    for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    delay(20);  
    /////////////////////
  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    HIGH);
  digitalWrite(pump2_direction,HIGH);
  digitalWrite(pump2_brake,    LOW);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    HIGH);
  
    for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    
     delay(2000);
    for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    delay(20);
  

      /////////////////////
  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    HIGH);
  digitalWrite(pump2_direction,LOW);
  digitalWrite(pump2_brake,    LOW);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    HIGH);
  
    for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    
     delay(2000);
    for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    delay(20);  
     /////////////////////
  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    HIGH);
  digitalWrite(pump2_direction,HIGH);
  digitalWrite(pump2_brake,    HIGH);
  digitalWrite(pump3_direction,HIGH);  
  digitalWrite(pump3_brake,    LOW);
  
    for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    
     delay(2000);
    for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    delay(20);  
     /////////////////////
  digitalWrite(stir_brake,     HIGH);
  digitalWrite(pump1_direction,HIGH);
  digitalWrite(pump1_brake,    HIGH);
  digitalWrite(pump2_direction,HIGH);
  digitalWrite(pump2_brake,    HIGH);
  digitalWrite(pump3_direction,LOW);  
  digitalWrite(pump3_brake,    LOW);
  
    for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    
     delay(2000);
    for (int motorspeed = pump_speed; motorspeed >= 0; motorspeed--) {
      analogWrite(44, motorspeed);
      delay(pump_ramp);
    }
    delay(20);  

  
}
26  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 01:29:00 pm
This is the offending code

Code:
for (int motorspeed = 0; motorspeed < pump_speed; motorspeed++) {
    analogWrite(44, motorspeed);  

int motorspeed = 0;

Every time thru the loop it initializes motorspeed to 0. I need a for next loop that will let me use a variable that has already been initialized in setup maybe.
27  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 12:15:31 pm
The function is one of many states in a state machine. I had relays driving the pumps and the timer stuff worked well. But when I added the pwm routine the ramp up loop runs several times in the  function  while running.
28  Using Arduino / Programming Questions / Re: PWM motor speed question on: April 16, 2013, 12:11:35 pm
Quote
by the way, on the closer look i must ask, in what interval you are calling this void from ouside code? because if it is less than one second, you never step inside first "if" and do not print seconds and do not test FILLING_TIME and do not ramp down the pump ....

This just keeps the display from flickering. It prints the screen if counter is less than 2 then keeps the counter less tan 5. Without this the counter overflows and the display begins to flicker
29  Using Arduino / Programming Questions / Re: avrdude: stk500_getsync(): not in sync: resp=0x00 on: April 16, 2013, 11:30:39 am
I get this from time to time. Unplugging ad replugging USB, Changing port number assigned, Plugging in another unit or rebooting are the things that seem to work.
30  Using Arduino / General Electronics / Re: can someone reccomend me an entry lever scope please on: April 16, 2013, 11:14:44 am
I have a TENMA 25 MHZ that I swapped for ($50 value)and it works for most things. Usually you don't need to measure the freq of a signal you need to see of if is there or if it is changing. For Finding noise it is quite sufficient. But an LA is another matter.
Pages: 1 [2] 3 4 5