Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pinguino4550 H-Bridge control with PWM ECCP1
28-01-2015, 11:05 PM,
#1
Pinguino4550 H-Bridge control with PWM ECCP1
Hello everyone,
I am working on an H-bridge DC motor control and I added some new functions on pwm.c lib for controlling the enhanced CCP1 of 18F4550.

Here is the list of the new functions:
-PWM_setEnhancedOutput [adapted from mplabc18]
-PWM_setDeadBand [for Half-Bridge]
-PWM_setASautoRestart [auto-restart after autoshutdown]
-PWM_setASmanualRestart [manual-restart after autoshutdown]
-PWM_setAutoShutdown [at the moment configure only input FLT0 able to shutdown the bridge].
I am still testing on my Pinguino4550. In theese functions there is no control for the processor if it has or not the Enhanced CCP capability.
Can you help me to check the code or readapt for the best usage?
Thanks
Luca


Attached Files
.c   pwm.c (Size: 12.89 KB / Downloads: 11)
.pde   HBridge_18F4550.pde (Size: 2.5 KB / Downloads: 16)
Reply
30-01-2015, 02:01 PM,
#2
RE: Pinguino4550 H-Bridge control with PWM ECCP1
(28-01-2015, 11:05 PM)brikker Wrote: Hello everyone,
I am working on an H-bridge DC motor control and I added some new functions on pwm.c lib for controlling the enhanced CCP1 of 18F4550.

Here is the list of the new functions:
-PWM_setEnhancedOutput [adapted from mplabc18]
-PWM_setDeadBand [for Half-Bridge]
-PWM_setASautoRestart [auto-restart after autoshutdown]
-PWM_setASmanualRestart [manual-restart after autoshutdown]
-PWM_setAutoShutdown [at the moment configure only input FLT0 able to shutdown the bridge].
I am still testing on my Pinguino4550. In theese functions there is no control for the processor if it has or not the Enhanced CCP capability.
Can you help me to check the code or readapt for the best usage?
Thanks
Luca
Hi Luca,
Recently I worked with a L293D chip to control 2 DC motors driving a wheel each. Look at my below example which is on purpose simplified !
For each motor the speed is controlled by PWM, here got by an analogWrite(pin, value), connected to the enable pin on the L293D; the direction by a digital output. A third signal is made by a transistor inverting the direction signal.
Is-it possible to replace the L293D by the Microchip PWM module ? If yes what coding (configuration, mode, etc ...) I have to write. The datasheet is a bit difficult for me to understand.

int const PWMA = 4; // left DC motor

int const PWMB = 5;
int const dirA = 0; //left
int const dirB = 1;
int const speedBot = 1000;
char forward;

void setup() {
pinMode(PWMA, OUTPUT);
pinMode(PWMB, OUTPUT);
pinMode(dirA, OUTPUT);
pinMode(dirB, OUTPUT);
forward =1;
}

void loop() {
if (forward){
digitalWrite(dirA, HIGH);
digitalWrite(dirB, HIGH);
}
else { //backward
digitalWrite(dirA, LOW);
digitalWrite(dirB, LOW);
}
analogWrite(PWMA, speedBot);
analogWrite(PWMB, speedBot);
forward= !forward;
delay(10000);
}


NB : I use a 18f47j53 but I think it is similar for that to a 18f4550.
Thank you for your help.
André
Reply
07-02-2015, 11:53 AM,
#3
RE: Pinguino4550 H-Bridge control with PWM ECCP1
Hi André,
I think it is not possible, internal CCP1 can manage only one Full or Half bridge.
Consider also that you should add external circuit to drive the motor (e.g bjt, mosfet etc).
PICs cannot drive motor directly.
If you need to drive 2 separate DC motors, in my opinion, L293D (up to peak 1.2A) is a good solution.
Thanks
Luca
Reply
07-02-2015, 06:27 PM,
#4
RE: Pinguino4550 H-Bridge control with PWM ECCP1
Hi Luca,
Many thanks for your response. Now I know indeed the L293D was the alone solution for me.
Anyway would you give a schematics for the external circuit you recently experiment and the associated code to drive a DC motor. Just to better understand the precise role of the PWM functions you added in pwm.c. Thanks in advance.
Bye
André
Reply
10-02-2015, 12:24 PM,
#5
RE: Pinguino4550 H-Bridge control with PWM ECCP1
Hi Luca,
I've modified the PWM library and extended the keyword list.
Update will be published soon in Pinguino v11.

New functions are :

  • PWM.setEnhancedOutput
  • PWM.setDeadBand
  • PWM.setASautoRestart
  • PWM.setASmanualRestart
They are all surrounded with :

#if defined(__18f4550)
...
#else

#error "Enhanced PWM modes not available or not yet supported for your processor."
#endif until someone add support

until someone add support to another processor.

Thank you for this work.
Régis
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)