Notifications
Clear all

Possible power supply interference problem

24 Posts
5 Users
6 Likes
1,422 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6893
 

@valkrider Have we verified that the arduino pot pin is pinMode(x, INPUT_PULLUP); where x is pin #.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@valkrider)
Member
Joined: 3 years ago
Posts: 16
Topic starter  

@zander I don't think so this is the code from the earlier article on here

/*
  Stepper Motor Test
  stepper-test01.ino
  Uses MA860H or similar Stepper Driver Unit
  Has speed control & reverse switch
  
  DroneBot Workshop 2019
   https://dronebotworkshop.com 
*/

// Defin pins

int reverseSwitch = 2;  // Push button for reverse
int driverPUL = 7;    // PUL- pin
int driverDIR = 6;    // DIR- pin
int spd = A0;     // Potentiometer

// Variables

int pd = 500;       // Pulse Delay period
boolean setdir = LOW; // Set Direction

// Interrupt Handler

void revmotor (){

  setdir = !setdir;
  
}


void setup() {

  pinMode (driverPUL, OUTPUT);
  pinMode (driverDIR, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor, FALLING);
  
}

void loop() {
  
    pd = map((analogRead(spd)),0,1023,2000,50);
    digitalWrite(driverDIR,setdir);
    digitalWrite(driverPUL,HIGH);
    delayMicroseconds(pd);
    digitalWrite(driverPUL,LOW);
    delayMicroseconds(pd);
 
}

--
Colin
My website


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6893
 

@valkrider Ok, not applicable. Have you made sure no int value is wrapping around? Not sure how/why it only happens with the CNC attached however, maybe more load? Might just try changing the key variable to long.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1656
 

Hi Colin @valkrider,

   Maybe Ron (@zander) was closer than he realised ... I don't recall you mentioning a "reverse" switch input .. and that looks much more vulnerable than the speed control ... depending on the circuit associated with the switch.

By default, I think the Arduino system tends to set GPIO pins to  "INPUT" but not "INPUT_PULLUP".

A potentiometer (slider pin) output to the Arduino ADC needs "INPUT" (NOT "INPUT_PULLUP"), because the potentiometer is defining the voltage sent to the ADC.

-----------

"INPUT_PULLUP" should ONLY be applied to a digital input ... it means that there is a resistor of (say) 50kOhm internally connected within the Arduino microcontroller, between the 5V chip supply (or 3.3V if its a 3.3V chip)  and  GPIO pin. Thus if the pin is unconnected, externally, the pin voltage will be 5V, and read as "1" or "high".

Then, if (say) a push button switch of the "push to make" type is attached between the GPIO pin and ground, then when the button is pushed, the pin is connected to ground, and the pin will read as "0" or "low".

It is possible, and in some circumstances desirable, to provide an external resistor to do the pullup function, but in the absence of that external part, it is essential that the pin is defined in the program as "INPUT_PULLUP".

---

Push button switches are notorious for giving switch bounce problems, so I would recommend adding an external pullup resistor between the chip supply voltage (5V for most Arduinios, 3.3V for ESPs and others) and the Switch GPIO pin, and a capacitor between the Switch GPIO pin and ground. Typical values might be 10 kOhms and 0.1 microFarad, but they are not usually critical.

You may note I am suggesting a resistor value somewhat lower than the 50 kOhm internal resistor ... this lower value will reduce its sesitivity to electrical noise, and the capacitor will similarly help.

----------------

So in summary:

  The first step is to add pin type definition line ... possibly   

          pinMode (reverseSwitch, INPUT_PULLUP);     

  into the "setup()" function, alongside the other similar code lines.

----------

At this point I would check that it still works, at least as well/poorly as before, but hopefully much better. 

Only when happy that this has not introduced a new problem, I would proceed to the second step:

----------

Add a resistor and capacitor, to the switch wiring as described, to reduce the chance of noise pickup and switch bounce. Again check to see if it works, etc.

----------

Good luck, Dave

 


   
ReplyQuote
(@valkrider)
Member
Joined: 3 years ago
Posts: 16
Topic starter  

Dave (@davee) thanks for that suggestion. I don't actually need the reverse function and so I think I will remove the code and the switch. I think that you may be on to something in that on occasion the stepper motor goes into reverse by itself. I will go out to the workshop in the morning and reprogram the Arduino sketch to remove the reverse function. The ferrites have just arrived from Amazon so I will add a couple of those too.

Colin

--
Colin
My website


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6893
 

@valkrider Do one thing at a time so we know which is the solution.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
DaveE and Valkrider reacted
ReplyQuote
(@davee)
Member
Joined: 3 years ago
Posts: 1656
 

 Hi Colin @valkrider,

   A Ron (@zander) says, do 1 change at a time, so you have a chance of finding out the real cause.

  I suggest you start by adding the pinmode instruction I suggested, and see if it works ... including still supporting reverse.

Of course, I am not suggesting you keep the reverse function permanently if you don't want it .. just long enough to test out the effect.

Good luck, Dave


   
Valkrider and Ron reacted
ReplyQuote
(@valkrider)
Member
Joined: 3 years ago
Posts: 16
Topic starter  

Dave (@davee) Thanks for the suggestion about the code change. I put that in and it worked fine, I could run the CNC motor to full speed without issue. I then redid the sketch removing the reverse code and disconnected the push button from the Arduino and that worked fine too. So I will leave it like that.

Thanks to everyone on here for all the suggestions and advice. I will put a comment on the original blog post about the suggested code change and link to this thread.

--
Colin
My website


   
DaveE reacted
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6893
 

@valkrider I am glad the code change I suggested worked.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
Valkrider reacted
ReplyQuote
Page 2 / 2