Need to know if the project I have planed can be done

I hope I'm in the right place , if not please relocate to proper place .
I have a project that I would like to build using a Arduino & I need to know first if its possible & if it can be done with a Nano , Uno or Mega & what order the code should be in .
I have a metal lathe that is run a treadmill motor
I would like to read the RPM using a reed switch or another type switch hooked up tp my Arduino .
The treadmill controller that has a PWM input . I would like to use a 4 x 4 keypad to control the speed by inputing the desired numbers / speed on the keypad then pressing the A to start & pressing the B to stop .
I would like to use the C # D keys to raise or lower the speed . And possibly use the & the # to switch a relay to reverse the speed .
Does a Uno have enough power to do this or can / will I need a smaller or larger Arduino ?
I'm borderline Dyslexic so I realize that I will make tons of mistakes .
I think I would want the motor to not power on until I use the keypad for safety . I know that PWM has a range of 0-255 . Can a PWM number have a decimal point with numbers on each side of the decimal ?
I know that my lathe cannot handle the full speed of the motor so I will have to put a limit of some type in the code once I figure out what the max limit PWM amount is for m y motor .
I have no idea of what the sequence of my code should be as fast as what does what when .
I’m sure I’m missing some things , but I think this is enough to see if this project can grow any teeth .
Sorry about jumping all over the place , its kinda how I type .

Thanks
animal12

1 Like

Overkill was my first impression.
Lathes, even the most basic, usually come with a variety of pulleys in place to give a wide variation in speeds.
Sufficient for 99.9% of everyday requirements , using a standard single or dual speed split phase motor, simply by slipping the belt over the next appropriate pulley pairs.

1 Like

For an AC motor, get a VFD, Variable Frequency Device. For DC motors there are several possibilities.

Ok let me rephrase this . How about I change it to say I have a tread mill motor , not a lathe motor .I realize there are several possibilities to control a DC motor . Unfortunately they are not within my budget . i have all of the Arduino components mentioned .
thanks for the input
animal12

Sorry but "tread mill motor" doesn't contain enough information. What brand, what type, what modell? A link to the pruct desription would likely help.

1 Like

Yes.

The code is simple enough and an Arduino UNO or similar board would be up to the task.

You will need external circuitry to control power to the motor. This is often the source of as much challenge as making the code work, if not a larger problem in itself.

Reading the RPM is another challenge, but there are many ways to do it.

PWM is indeed in integer 0..255, do you think you need finer resolution on the speed? With a bit of extra circuitry, that range could cover just barely moving to full allowed speed.

Maybe a bit more than a bit more. If you were only able to use 66 (just starts to move) to 200 (max speed you want) would that many steps suffice?

What kind of project have you done that is anywhere near this level of undertaking? It's not especially hard, but if all you've done is blink an LED you may be throwing yourself into deep water.

a7

1 Like

And, finally, please confirm that you lathe/treadmill motor is operational right now and it is using the original treadmill power supply and speed control!

2 Likes
Alto ,  thanks . Yes I know this could be a complicated project .The only other project I have done is to motorize a rotary table with a stepper  , it works but still needs a little work , which I realize . The more control I can have over the PWM input to the motor controller the better I could control the RPM I would think . The motor has a seperate fan so I know I can run it slow enough to tap with . I bought one of these to see if I could get a better understanding of the  PWM requirements & range of my motor .
Paul , currently the machine is operational with a micro board I bought off a guy in one of the forums , but It has always had a bit of a glitch in the starting function & I would just as soon replace it . The micro board sends the PWM signal into the factory MC2100 TM motor controller through the PWM input pin on the MC-2100 . 
Railroader , I do not have the motor #'s with me the machine is at another location , but like mentioned I'm using a MC-2100 TM motor controller . I believe this is the motor https://www.surpluscenter.com/Electrical/DC-Motors/Special-Purpose-DC-Motors/3-HP-4725-RPM-130-Volt-DC-Icon-Health-And-Fitness-Treadmill-Motor-M-326338-10-3031.axd I do not believe the actual motor is needed to get the keypad to MC2100 part started / working . 



This is all thought process for now . I'm getting ready to go on a trip but wanted to have some input to think about while gone .
If  I can find a good simulator I can try to do some work on it in the evenings while traveling .
I know the motor runs , I think maybe one of the first things I need to know is which order do I put things in the code ?

1 . power on 
2 . input desired RPM into keypad to start motor 
3 . read rpm
4 . press A to start the motor & run to desired rpm 
5 . press C or D to either raise or lower RPM of motor 
6 . press # or * to operate relay to change direction

I have done a lot of searching but " I " have been unable to find anything on how to convert numerical input to a desired RPM 




thanks , appreciate any help/guidance on this 
animal12
1 Like

Do you remember that ALL motors require more current to just get started? Once beginning to turn, you can reduce the current. And you can do all that with your program.

You left the most important part out!
What treadmill controller do you have?

If your lucky that would be a mc-2100 if so I have code and much info about that particular one.

EDIT: I missed that you do have the mc-2100.
That's a good controller and you do not need the pwm signal generator the arduino can handle it just fine and with 5300 steps of resolution between 0-85% power.

2 Likes

Yea , Paul the controller MC-2100 handles the motor startup fine with no issues .
Hutkikz , can you please point me in the direction where 5300 steps is explained ? That # is totally new to me
The reason I got the pwm signal generator ws so I can put a tach of some sort on my machine & read where in the 0-255 range I reach max rpm of what my spindle can handle . I figured I would need to know what the max pwm input was so I wouldn't over rev my spindle & that I would somehow put that max pwm # in the code somewhere so the code knows where to stop ? Does that make sense to you ?
thanks
animal12

1 Like

This code produces the 20hz PWM signal required by the MC-2100. By manipulating the Arduino timers directly we can achieve the 5300 steps of resolution.

Because the 2100 has closed loop feedback (has provision for tach input) this code is limited to 85% max dutycycle. This allows the closed loop circuit to attempt to maintain the RPM under load. I recommend using the Tach Input as it's not hard:

This test code uses a potentiometer for the getDutyCycle() function. So it is only capable of 10bit(1024 steps) resolution because it is constrained by analogRead(). A keypad will not be so constrained.

However the applyDutyCycle() function can handle any number from 0 - 5300 steps of resolution. Just remember that the motor will not start moving till around ~15-20% dutycycle.
And yes you can limit the speed to anything you like in the code.

/* ================= HEADER ==================
   PROJECT: Treadmill speed Control
            Using a MC-2100 controller that requires a 20 hz phase correct 
            PWM signal on Pin 9 with a 0-85% dutycycle

   VERSION: 0.0.2

   IDE VERSION: 1.8.9

   HARDWARE: Nano (328p)
             Potentiometer
             MC-2100 REV.B Motor Controller
             Treadmill Motor
*/

// ================= CONSTANTS ================
constexpr uint8_t PWM_PIN = 10;
constexpr uint8_t SPEED_POT = A0;
constexpr uint16_t MIN_DUTY = 0;
constexpr uint16_t MAX_DUTY = 5300; // 85% of TOP_COUNT

// ================= VARIABLES ================


// ================================================================
// *                              SETUP                           *
// ================================================================

void setup()
{
  pinMode(PWM_PIN, OUTPUT);

  // Initializes timer 1 to produce a 20 hz pwm
  init20hzPWM();

}// End setup()


// ================================================================
// *                       MAIN PROGRAM LOOP                      *
// ================================================================

void loop()
{
  applyDutyCycle(getDutyCycle());
  
}// End loop()


// ================================================================
// *                       getDutyCycle()                         *
// ================================================================

uint16_t getDutyCycle()
{
  uint16_t rawPot = analogRead(SPEED_POT);
  uint16_t dutyInput = map(rawPot, 0, 1023, MIN_DUTY, MAX_DUTY);
  return dutyInput;
}// End getDutyCycle()


// ================================================================
// *                       applyDutyCycle()                       *
// *                        *
// ================================================================

void applyDutyCycle(uint16_t dutyCycle)
{
  // Constrain dutycycle within range
  if(dutyCycle > MAX_DUTY) {
    dutyCycle = MAX_DUTY;
  }

  static uint16_t oldDutyCycle;
  if (oldDutyCycle != dutyCycle)
  { 
    oldDutyCycle = dutyCycle;
    
    // setting OCR1x applies dutyCycle
    OCR1A = dutyCycle;
  }
}// End applyDutyCycle()


// ================================================================
// *                       init20hzPWM()                          *
// *  Set up Timer1 for 20hz phase correct PWM output on pin 9    *
// ================================================================

void init20hzPWM()
{
  // clock divisor
  constexpr uint16_t PRESCALER = 64;

  // Desired Frequncy in Herz
  constexpr uint16_t FREQUENCY = 20; 
  
  // Formula derived from Secrets of Arduino PWM 
  // (http://www.righto.com/2009/07/secrets-of-arduino-pwm.html)
  constexpr uint16_t TOP_COUNT = F_CPU / PRESCALER / FREQUENCY / 2; 

  // Set prescaler to /64
  TCCR1B |= (1 << CS10) | (1 << CS11);
  
  // Set WGM mode 10 - phase correct pwm using ICR1 as TOP
  TCCR1A |= (1 << WGM11);  
  TCCR1B |= (1 << WGM13);
  ICR1 = TOP_COUNT;

  // Set Timer1 to output on pin 9(OC1A)
  TCCR1A |= (1 << COM1A1); 

  // setting OCR1x applies dutyCycle
  // initialize to 0(off)
  OCR1A = 0;   

}// End init20hzPWM()

Edit:
I would like to add that it is possible to read the Tach Input directly from the MC-2100. I just never got around to implementing that feature. But I would be willing to work on that if you want to test it for me.

Thank you very much Hutkikz . I will be spending some time trying to learn how/what the code does . I watched pretty much all DazeCars youtubes on Treadmill's & controllers . I do have the reed switch for the tach on the MC-2100 hooked up reading the pulley on my motor for now . From the reading I have done on the MC-2100 I understand that the onboard tach act's as feedback to keep the motor at set speed under load . So my thought was that if I'm cutting & start to bog the motor down the tach will tell the motor that it has slowed down some & bring it back to set speed . Am I understanding that part right ? So your saying that the arduino can read the tach from the 2100 ? I thought that I was going to need a seperate tach . That sounds interesting . So I'm still trying to figure out where the " 0 - 5300 steps of resolution " comes from . I do get the motor not starting till around 15-20% duty cycle & the 85 % max part . Sounds like you've spent some time with these MC-2100's . I have a MC-60 & a MC-40 which both work with just a pot , but I have other plans for those motor's & controllers .
thank you very much
animal12

1 Like

That's correct.

That's harder to explain. Basically the Arduino derives PWM by dividing it's 16Mhz system clock cycles into appropriate sized chunk's then simply counts cycles to achieve the desired frequency. The dutycycle is then a percentage of those cycles with 100% dutycycle being a full count.
In this case a 20hz frequency equals a count of 6250 clock cycles. Since we do not want to go past 85% dutycycle. 85% of 6250 is 5300.

If you wish to learn more see: Secrets of Arduino PWM

Thanks again Hutkikz , I saw the link for the secrets of PWM in the code so I have been reading & rereading . It will take some time before it kicks in . I also need to spend time reading the comments for that article . I know sometimes the real gem in in one of the comments . OK I kinda get where the 5300 came from , so I need to keep that in mind as I read more .
thank you much
animal12

1 Like

Keep that up and it won't take long. :nerd_face:

Here is the original blog posts about this board from 2013.
I think everything since is based on these guys research .
They never finished it.
but near the end there is info nobody else has noticed.
check it out:

1 Like

IS you spindle in sleeve bearings? If using tapered roller bearings, as it should, there is no over rev possible.

Hutkikz thanks I started out on the Sons of invention page several years back , I even built the 555 circuit , but life & health tossed a stick in my spokes . One of the guys that posted in that article abandoned his setup to use the PWM generator I mentioned earlier , he has a couple of youtubes out there somewhere about using the generator .I I'll have to give the Sons another read to see if I can't catch what you mentioned towards the end of the page .
Paul , thanks yes my South Bend lathe has plain bearings .I believe the max rpm for that spindle is 1500 rpm I will do another search on the Practical Machinist forum that info is there . My much, much newer ENCO lathe has real bearings . This project is aimed towards the SB late first . If I can get this to work Step 2 would be installing another setup on my Vertical mill , & then maybe the ENCO , I don't know for sure . After 30+ years as a contractor my hands do not work very good a lot of the time & sometimes something as simple as changing the belts on these machines is enough to stop me from any planned work . SO that in a nutshell is the reasoning behind this project .
thanks folks
animal12

Ahh, I wasn't aware of any content beyond that blog. But,I'm not surprised that he gave up he was having major issues and then it just petered out.
Since Your already familiar. The info I was referring to was the fact that on his original treadmill the reed switch was not on the motor pulley but on the driven pulley that runs 50% slower than the motor pulley. I confirmed this on my own treadmill.
This means the board expects a Tach signal that is 50% of motor speed!

Now I am not sure if that means anything. The Sons of Inventions guy thought it was what was causing the issues he was having at the time tho I am not sure I agree. On my drill press I planned to build a circuit to emulate that but in 8 yrs it never happened and having the reed switch on the motor pulley worked as well as Dazecar's But you can see on his video that it has a bit of lag to it as did mine. I keep thinking that if it was getting the signal as originally designed it might not lag so much.

1 Like

OK , I missed that part , but my plan is/was to have my tach pickup on the actual spindle . On all the TM's I've salvaged the pickup was mounted on the driven/large pulley . I kinda lucked out when I started getting my hands on TM's cause 3 had MC-2100 , then a MC-60 & a MC 40 . I also got my hands on a commercial TM & that guy came with a awesome motor , unfortunately there is no reverse engineering anywhere on the controller for that motor . A guy that used to repair TM's told me that that was the best motor a guy could get his hands on for a lathe or a mill . Also fortunately the motors off the MC-2100 TM's have a separate fan so I don't have to worry about cooling after I pull the flywheel /fan off . I still plan to use a seperate computer fan for cooling , just to be on the safe side . Unfortunately I lost the chokes & 2 of the reed switches , so I will have to get those at some point .
thanks
animal12