View previous topic :: View next topic |
Author |
Message |
ressas
Joined: 15 Nov 2019 Posts: 135
|
Half bridge with 18f46k22 direction problem[SOLVED] |
Posted: Tue Oct 06, 2020 7:25 am |
|
|
Hi
I took a quick look at the topics related to Half bridge on the forum.
But I could not find the solution. My code is as follows.
Code: |
#include <18f46k22.h>
#INCLUDE <stdlib.h>
#fuses INTRC_IO,NOWDT,NOBROWNOUT,PUT,NOWRT,NODEBUG
#fuses NOMCLR, NOPROTECT, NOWDT, NOLVP, PLLEN
#use delay(clock=64000000)
void main(void) {
output_c(0x00);
output_d(0x00);
setup_timer_2(T2_DIV_BY_4,99,1); //100 us overflow, 100 us interrupt
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L | CCP_PWM_H_H);
set_pwm1_duty((int16)50);
output_drive(PIN_D5);
output_high(PIN_D4);
while(TRUE) //This avoids the compiler error message
{
set_pwm1_duty((int16)722);
if(input(pin_b0)){
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L | CCP_PWM_L_L);
}
else
{
setup_ccp1(CCP_PWM|CCP_PWM_HALF_BRIDGE|CCP_SHUTDOWN_AC_L|CCP_SHUTDOWN_BD_L | CCP_PWM_H_H);
}
}
|
Here I am trying to change the direction of the motor with the button. But somehow I could not achieve this. I don't know how logical it is to use "setup_ccp" again in "while (1)" anyway.
How can I control the direction with the button?
Last edited by ressas on Wed Oct 07, 2020 11:06 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Tue Oct 06, 2020 8:05 am |
|
|
Er....
A half bridge, normally can't change direction. That is the critical difference
between this and a full bridge.....
You can only change direction with this if you use a split PSU, and then you
wouldn't drive it as a half bridge, You would just drive the upper transistor
for 'forwards', and the low one for 'reverse'. |
|
|
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Tue Oct 06, 2020 10:51 pm |
|
|
I'm sorry to hear that.
Doesn't the circuit on page 187 mean that I can actually change direction? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Wed Oct 07, 2020 1:12 am |
|
|
Page 187 of what?.... |
|
|
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Wed Oct 07, 2020 1:26 am |
|
|
18F46k22 page 187 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Wed Oct 07, 2020 1:35 am |
|
|
Which has a split supply. Do you have this?.
With this you can drive both ways, but you don't then drive
the PWM as a 'half bridge'. For forward you just drive PxA, and for
reverse PxB.
To do it with half bridge drive offering reversing, you
have to use the second circuit on that page, with the half bridge
outputs driving a full bridge circuit. |
|
|
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
Posted: Wed Oct 07, 2020 4:35 am |
|
|
I have no split PSU.
And the second circuit I'm talking about.
Now can't I control that circuit in both directions using ccp1 (pin_c2) and pin_D2?
With a single PSU. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19512
|
|
Posted: Wed Oct 07, 2020 7:09 am |
|
|
That's a full bridge driver, not a half bridge.
With that circuit, the same comment applies. You don't want the half bridge
code, just single PWM outputs. Set the PWM to output on PxA, and the
motor will drive in one direction. Set it to use PxB and it'll go the other.
So CCP_PULSE_STEERING_A for one direction and B for the other. With
CCP_PWM. No bridge code involved. |
|
|
ressas
Joined: 15 Nov 2019 Posts: 135
|
|
|
|