PWM to Stepper code help

Hello,
I found the code attached to this post and thought it might work for my project. Although the more I look at it I begin to think that it won't work for me, I was hoping someone might be able to take a look at it and clear up a few questions.

Basically, I have a PWM signal that needs to go through the Arduino nano and out to a easy driver stepper driver (ROB-12779)

Will this work to accomplish this if I connect the PWM wire to pin 0?
I believe the PWM signal is a ground and doesn't supply voltage. I feel as though the Arduino would have to reference 5v somehow, is this possible?

Originally there was a PWM valve that was supplied with a 12v wire and this PWM circuit but I must use a stepper version now in order to accomplish my goals. Any help is much appreciated, thanks.

PWM_to_STEPPER.ino.ino (991 Bytes)

Please post your code to make it easy to download to an editor for examination and testing if needed

Please follow the advice on posting code given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

are you suggesting that an arduino input a PWM signal representing a voltage applied to a DC motor and presumably determining that motors speed to control the speed of a stepper motor?

if so, shouldn't the PWM value determine the time between steps?

const int stepPin =   2;
const int dirPin  =   3;      
const int inPin   =   A0;
int input         =   0;
int currentpos    =   255;
const int PWRPin  =   4;

void step(int count);

void setup() {
  // put your setup code here, to run once:
  pinMode(stepPin,  OUTPUT);
  pinMode(dirPin,   OUTPUT);  
  pinMode(inPin,    INPUT); 
  pinMode(PWRPin,   OUTPUT); 
  digitalWrite(PWRPin, HIGH);


 
  //Home the piston to wide open.
  digitalWrite(dirPin, LOW);
  step(260);  

}

void loop() {


input = analogRead(inPin) / 4;



// if the input is LOW, DIR = 1, and make one step
if(currentpos > input)
{
digitalWrite(dirPin, HIGH);
step(1);  
currentpos = currentpos - 1;

}

// if the input is HIGH, DIR = 0, and make one step 
if(currentpos < input)
{
digitalWrite(dirPin, LOW);
step(1);
currentpos = currentpos + 1;

}

}


void step(int count) {
  
while (count > 0)
  {
  digitalWrite(stepPin, HIGH);
  delay(4);
  digitalWrite(stepPin, LOW);
  delay(4);
  count--;
  
  }

  return;
}

oops should have read the rules more carefully. Here is the code.

gcjr:
are you suggesting that an arduino input a PWM signal representing a voltage applied to a DC motor and presumably determining that motors speed to control the speed of a stepper motor?

if so, shouldn't the PWM value determine the time between steps?

Yes it is supposed to input a PWM signal then translate that and output to a stepper driver. The PWM signal is created by a engine management computer that determines what to send based on Coolant temp. lower temp = open the valve, higher temp = Close the valve.

player1pressstart:
Yes it is supposed to input a PWM signal then translate that and output to a stepper driver.

yes, but should it determine speed?

it looks like your code interprets it as a position.

It should not determine its speed. Yes it should interpret the PWM as a position to move the plunger to.

how to you determine the zeroth position of the stepper motor on start up.

Wouldn't this move it out to its max reach and home it?

 //Home the piston to wide open.
  digitalWrite(dirPin, LOW);
  step(260);

so if its reached its end of travel, the code keeps forcing it further?

why not use a limit switch and stop it?

There is no space for one unfortunately, this is a idle air control valve in a throttle body for a car.

As it sits would a PWM signal work to move the stepper motor?

a pulse width modulated signal is a binary (having 2 possible values) signal that switches values within some period of time to represent an analog voltage based on it's average value. a stepper motor is driven with at least 2 binary voltages that alternate polarity. their order determine direction.

so a single PWM signal cannot directly driver a stepper motor. but the code you posted measures the PWM signal (presumably RC filtered) to determine a value between 0 - 1024 which can be used to represent a position a stepper motor is driven to.

the code drives the stepper with a stepper driver circuit that has a direction and step pulse input

so the code along with some circuitry appears capable of doing what you describe

Ok. Good info, thank you. I'll wire it up tonight and try this code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.