Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

switch woes

Status
Not open for further replies.

desijays

New Member
Hello everyone,

I have managed to control a DC motor using the pwm module on the 16f877a. I tried to vary the duty cycle and it worked flawlessly although at 20% or less duty cycle the motor would not even turn.

Now I want to control the direction of rotation of the motor based on user input. So I am using a small mechanical switch. It gets power from a 5V supply to simulate the logical high and logical low states.

So when the switch is "on" the output is a logical high or 5V. But when the switch is in the "off" state it does not output a logical low. Instead there is no measurable output what so ever... I believe logical low would be 20% to 25% of logical high. But in this case the switch output 0% in the "off" state.

Is there any alternate method I can use to perform the same or is there any modification I can make to the existing circuit to make it output a logical low?

Thank you.
 
Hi,
For an active high switch, you need a pull down resistor. When the switch is not on, the input pin will be pulled low.
 
Hello,

Is it any different from a normal resistor? If I am to buy it from a shop, what do I ask the shop keeper for, so that he knows I want a 'pull down' resistor and not someother resistor? And what ohms?

sorry if that question sounds naive!

Thank you
 
It is just a resistor. Terms like pull up, pull down, and current limiting refer to the way it is used.

Use a 10K resistor between the input pin and ground, that will keep the input low as long as the switch is open. The switch goes between the input pin and +5. When the switch is closed the pin goes high.

You can also do a pull up. Use the 10K resistor between the pick input and +5. The switch is tied to ground. When you close the switch the voltage at the pin goes low.

If you get the motor to turn at 20% duty cycle you are doing well. Below that the friction and other loses use up the energy and the motor will not turn.

Are you reversing the motor with an h-bridge?


desijays said:
Hello,

Is it any different from a normal resistor? If I am to buy it from a shop, what do I ask the shop keeper for, so that he knows I want a 'pull down' resistor and not someother resistor? And what ohms?

sorry if that question sounds naive!

Thank you
 
Last edited:
desijays said:
Hello,

Is it any different from a normal resistor? If I am to buy it from a shop, what do I ask the shop keeper for, so that he knows I want a 'pull down' resistor and not someother resistor? And what ohms?

sorry if that question sounds naive!

Thank you

hi,
You have not said which port on the PIC you have the switch, some port pins have weak internal pull up resistors that can be enabled by the program.

For a hardware resistor solution, I would suggest a 4K7 or 10K resistor, fom +5V to the port pin, if you plan to pull the port input Low.

This would give a resistor current of 1mA or 0.5mA, enough to 'wet' the contacts on most switches.

Do you follow.?
 
3v0 said:
Are you reversing the motor with an h-bridge?

hello 3v0,

Yes i am using the L298N dual h-bridge thing. That is how i managed to control the motor.

I will try the resistor you mentioned.

Thank you for clarifying that part about pull ups and pull downs.
 
ericgibbs said:
hi,
You have not said which port on the PIC you have the switch, some port pins have weak internal pull up resistors that can be enabled by the program.

For a hardware resistor solution, I would suggest a 4K7 or 10K resistor, fom +5V to the port pin, if you plan to pull the port input Low.

This would give a resistor current of 1mA or 0.5mA, enough to 'wet' the contacts on most switches.

Do you follow.?

hello eric,

I am using port D on the PIC. I think I'll try the hardware solution though. Are you talking about port B, when you mentioned 'some port pins have weak internal pull up resistors'?

And yes, I do follow 75%. When I try it out, I'll understand 100%.

Thank you.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top