CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Half bridge with 18f46k22 direction problem[SOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

Half bridge with 18f46k22 direction problem[SOLVED]
PostPosted: Tue Oct 06, 2020 7:25 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 8:05 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Oct 06, 2020 10:51 pm     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 1:12 am     Reply with quote

Page 187 of what?....
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 1:26 am     Reply with quote

18F46k22 page 187
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 1:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 4:35 am     Reply with quote

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: 19195

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 7:09 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Oct 07, 2020 11:12 pm     Reply with quote

Thank you Ttelmah.
I am understand.
By the way I found a nice open source H Bridge and tried it.
It does not heat at all (at 2 Amps). If you use it with a fan, it says it works up to 40 amps.
https://www.electro-tech-online.com/articles/open-source-h-bridge-dc-motor-driver.906/

Two different pwm channels must be used to drive.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group