Controlling the direction of the motor

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

HI all, i am trying to control the direction of the motor forward or bacward, i am giving out signal, by using DAC from Potentiometer. i am working on KIT number CY8C29466-24 SXI.

   

If anyone can help me to figure out how to control that would be great.

   

 

   

Thanks

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

It is always not adviseable to connect an inductance (motor coil) directly to any digital circuit, even when the motor is a very small one. There are interfaces named H-Bridges giving you full control over the direction of the movement, strength (voltage) and torque (with PWM), even the start-stop behaveour may be controlled.

   

An H-bridge may be made of 4 separate transistors or may be contained in an IC, look here

   

http://en.wikipedia.org/wiki/H_bridge

   

Bob

View solution in original post

0 Likes
54 Replies
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

 Hi,

   

For a guide to controlling and measuring fan speeds, you can have a look at PSoC® 1 - Intelligent Fan Controller. The document and example project will help you count the tach pulses and you can drop in the equations to convert them to RPM.

   

 

   

If at all you need more resolution for controlling the speed of the motor, you can consider using a 16-bit PWM usermodule, instead of DAC. You will find these details in the appnote as well.

   

 

   

Regards,

   

Arvind

Anonymous
Not applicable

Hi Bob,

   

the modified code that you sent me is not function when i change the switches, once it goes to RUN and one of the direction CW or CCW, it gets stuck. i am not sure if i am missing something.

   

Thanks

0 Likes
Anonymous
Not applicable

it never comes out from for loop in the MoveMotor function

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

 Try replacing DAC9_WriteStall(x); with  DAC9_WriteBlind(x);

   

WriteStall might have some problems if interrupts are enabled and the latency is high.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

mins,

   

as someone lately said:"We can show you how to catch fishi, but we will not give you any fish".

   

When the program stays within a loop, try to find out why and alter the loop accordingly, we here do not have got the hardware you have got to test everything. As I could see, your programming skills are not yet fully developed, and you need a bit more practice. I would recommend  for syntax of C using this http://publications.gbdirect.co.uk/c_book/ book.

   

Since you are working with PSoC1 and you do not have got an ICE-Cube (In-Circuit-Emulator) it is very difficult to find out the reason if something goes wrong.

   

The PSoC3 and PSoC5 developement kits are equipped with a built-in debugging-feature (breakpoints, watching variables etc.) so to make your life easier i would suggest:

   

 

   

Buy yourself an ICE-Cube. Expensive, but it can show what goes on in your chip. Comes together with a pod for a CyC29466DIP

   

or

   

Buy a Kit-050 (cheaper) and develop / debug your software-modules there. That will teach additionally to write hardware-independant code. When the software runs, transfer the source to your target-PSoC.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 As Bob mentioned. it would be much better to have a proper debugging tools for development.

   

If that is not possilbe. One thing you can do is condigurate a UART and with a 232 interface, use priftf type message to a PC.

   

insert putstring or putchar in your program so you can see it from the PC hyperterminal.

   

I would also suggest you to do one little step a time

   

1. make sure you can control the speed of the motor with a fixed speed.

   

2. make a simple loop that increase or decrease the speed SLOWLY.

   

3. Make a loop that can change direction and change speed.

   

4. Generate pseduo sequence, ie make 1 sec up to 1/2 speed. 2 sec to reverse full speed...

   

5. Write code to read button correctly with debounce.

   

6. Combine that together.

   

Doing it one small step a time would save you time in the end..

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

my only problem in my code is, once i change the switch from CW to CCW, it turns direction right away ( it should wait till the speed slow down to zero then turn direction then speed back up again)..

   

i have CY3215- DK and i debugged code, but i only asked for how to make the bit dont change and wait till speed goes to zero.

   

Thanks anyway for help

0 Likes
Anonymous
Not applicable

1. Do not to use the CW and RUN direcly from the port, If those are key switches, it should be debounce. 

   

2. A static variable in main is no use.

   

3. you should only need to read the pot value once per loop.

   

4. Do you have some kind of flow chart or state diagram before you start the program, is the program same as your desing?

   

By the look of it, it seems to be a student project.

   

It is OK to ask people to have suggestions.

   

I know some teachers would go around to check if students are getting others to finish their homework. I saw that happended in other forums.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

@lleung

   

A static var in main() has a deep sense!

   

Any variable in a function (and main() IS a function) would be allocated on the stack, thus reducing it permanently because main() never ends. An alternative would be to define those vars globally, but then they would be accessable from any function, even by accident. Loop-vars needed in main() should NEVER be global, imagine the effort to find the error when a loop-variable is used in two different functions!

   

Declaring a variable within a function as static reduces the scope of the var to this function, but does not allocate it on the stack !

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Good point Bob.

   

It does help for 8051 and M8C which has a small stack.

   

Cheer:

0 Likes
Anonymous
Not applicable

I agree that we should avoid using global vaiable as well.

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

Globals are not all bad 🙂

   

 

   

I have an application in which several functions access a number of globals by intent,

   

almost all via pointers, variables are double. Saves a lot of FLASH, code space, by

   

using pointers to them. Variables not gettting passed on stack, code space and speed

   

conserved.

   

 

   

Hmmmmm, globals are good, when properly used.

   

 

   

Note machine architectural width affect efficiency of the above approach. So 8 bit

   

globals barely get any savings at all in PSOC 1/3 using the above approach.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

hi all, does anyone know how to change the direction of motor once the speed hit zero... it should works like motor is running, and once change dir switch should ramp down to zero -> change direction of motor -> ramp up to speed input.

   

thanks

0 Likes
Anonymous
Not applicable

May be you should do in one step a time

   

Use speed = 0x7f; //half speed.

   

Check the working of hardware first. Do not detect the buttons, just hardcode as following 3 tests.

   

1. Check if can work with CW direction

   

set dirrction to CW

   

while (1)

   

{

   

    slow down motor

   

    ramp up  motor

   

}

   

2. Do the same with direction set to CCW.

   

3.Check if can work for both direction: 

   

Change the loop as following

   

while (1)

   

{

   

   direction = CW

   

    slow down motor

   

    ramp up motor

   

   slow down motor

   

   direction = CCW

   

    ramp up motor

   

   slow down motor

   

}

   

Check the above first, come back with your result

0 Likes
Anonymous
Not applicable

thanks guys, i got it to work. now i get work on time capture.

0 Likes