I need to be able to change the direction and speed of a small dc motor using an PSoC LP5 and a L293D. The motor that was used is one of these: https://www.elecrow.com/dc-toy-hobby-motor-130-size-p-265.html. I was able to change the direction without PWM by changing the inputs, this gave me the following table.
But then I also had to change the speed. The schematics for this project can be found below. The PWM period has been set to 1000.
My code looks like this:
int main(void)
{
PWM_1_Start();
for(;;)
{
DIRECTION_Write(0);
PWM_1_WriteCompare(400);
CyDelay(2000);
// 2 seconds clockwise low speed
PWM_1_WriteCompare(0);
CyDelay(2000);
// 1 second nothing
DIRECTION_Write(1);
PWM_1_WriteCompare(400);
CyDelay(2000);
// 2 seconds counter-clockwise low speed
PWM_1_WriteCompare(0);
CyDelay(2000);
// 1 second nothing
}
}
The motor now only turns counter-clockwise, then stops for 5ish seconds en does the same again. I've tried other combinations such as also using SPEED_Write, but didn't get the result I wanted.
Any help is appreciated, thanks in advance :)
I've done exact thing with an L298, which I think is esentially the same as an L293. It's easiest to switch the EN pin and not the IN# pins. Move your PWM to EN1, and then control the direction with IN1 and IN2. When IN1 is 0 and IN2 is 1, the motor moves CCW. When the pins are reversed, it moves in the other direction. With a PSoC5 you can control both IN# pins with 1 signal. Add a 1-bit Control Register to your schematic and connect it to 2 pin components Then put a NOT gate between the second Gpio and the control register. Then you can write to the Control Register, and both Gpios will be toggled at the same time, but will always be the opposite of each other.