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

How can I use PWM FULL_BRIDGE?

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



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

How can I use PWM FULL_BRIDGE?
PostPosted: Wed Jul 01, 2009 9:31 am     Reply with quote

I want to drive H-bridge mosfet using pic16f684. But I couldn't solve how I can use this command;
Code:
setup_ccp1(CCP_PWM_FULL_BRIDGE)

Could you give any sample code for this operation?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 01, 2009 12:26 pm     Reply with quote

Use the forum's search page to find the answer:
http://www.ccsinfo.com/forum/search.php

One result of the search:
Here is a demo program for Full Bridge pwm mode.
http://www.ccsinfo.com/forum/viewtopic.php?t=29565&start=1
theasus



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 12:09 am     Reply with quote

Code:
#include <16f684.h>
#fuses XT,NOWDT,BROWNOUT,PUT
#use delay (clock=4000000)

//=================================
void main()
{

// Setup the ECCP for PWM in full bridge mode.
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
setup_timer_2(T2_DIV_BY_1, 255, 1);
set_pwm1_duty(100);
while(1)
  {
   // Run forward for 5 seconds.
   setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
   delay_ms(500);

   // Run in reverse for 5 seconds.
   setup_ccp1(CCP_PWM_FULL_BRIDGE_REV  | CCP_PWM_H_H);
   delay_ms(500);
  }

}


I have used these code but I couldn't get the result. I tried these codes and simulated on Proteus.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 12:36 am     Reply with quote

1. Post your compiler version.

2. How do you know for certain that Proteus simulates it properly ?
theasus



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 11:04 am     Reply with quote

my compiler version is 4.32
and my scheme is;
http://www.robotroom.com/BipolarHBridge/BipolarHBridgeSchematic.gif

my pic(16f684) pins are connected to output of this circuit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 11:11 am     Reply with quote

Quote:
my compiler version is 4.32

There is no vs. 4.32. See the versions page:
http://www.ccsinfo.com/devices.php?page=versioninfo
Look at the top of the .LST file for your project. It shows the compiler
version. The .LST file will be in your project directory.


Quote:
my pic(16f684) pins are connected to output of this circuit.

Is that a Proteus circuit or is that a real circuit in real hardware ?
theasus



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 1:03 pm     Reply with quote

the version of program is 4.032
I'm testing this circuit on proteus not with real hardware but if I could do this program I will. I think I have only one problem. My problem is how can I use these functions on 16f684?

setup_ccp1 (CCP_PWM_FULL_BRIDGE)
setup_ccp1 (CCP_PWM_FULL_BRIDGE_REV )


Do you have any sample code? I just want to drive H-Bridge.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jul 02, 2009 1:35 pm     Reply with quote

Your version of the compiler is buggy and it doesn't set the TRIS
correctly for the PWM output pins. This post shows how to fix it:
http://www.ccsinfo.com/forum/viewtopic.php?t=30755&start=7

In fact, the current version 4.093 also has this bug and needs the fix
shown in the link. I just emailed CCS support about this bug. It applies
to 16F684, 16F685, and 16F690. It also applies to Half-Bridge mode for
the P1A and P1B pins.
theasus



Joined: 31 May 2009
Posts: 79

View user's profile Send private message

PostPosted: Fri Jul 03, 2009 12:34 am     Reply with quote

First of all thanks for your help and consideration.
I have one more question

Code:

#include <16F684.h>
#fuses XT,NOWDT,BROWNOUT,PUT
#use delay (clock=4000000)

//=================================
void main()
{

// Setup the ECCP for PWM in full bridge mode.
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs
setup_timer_2(T2_DIV_BY_1, 255, 1);

set_pwm1_duty(75);


// Switch the H-Bridge outputs between forward
// and reverse every 5 seconds.
while(1)
{
// Run forward for 5 seconds.
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs
delay_ms(50);
// Run in reverse for 5 seconds.
setup_ccp1(CCP_PWM_FULL_BRIDGE_REV | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs
delay_ms(50);

}

}


And here is my circuit and my signal;



How I can fix my signal?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 4:30 pm     Reply with quote

I think it's working. But I think the bandwidth of your Proteus
oscilloscope is very poor.

Try a more simple test program. Look at just the Full Bridge PWM
mode in the Forward direction. Use the test program shown below.

Download the 16F684 data sheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/41202F-print.pdf
Look at this diagram on page 88 in the Acrobat reader:
Quote:
FIGURE 11-6: EXAMPLE PWM (ENHANCED MODE) OUTPUT RELATIONSHIPS (ACTIVE-HIGH STATE)

Look at the timing diagram called "Full Bridge, Forward".
It shows the following outputs:
Quote:
P1A: constant High level
P1B: constant Low level
P1C: constant Low level
P1D: modulated PWM signal

Try the following program and see if you get those output signals.
Code:
#include <16F684.h>
#fuses XT,NOWDT,BROWNOUT,PUT
#use delay(clock=4000000)

//=================================
void main()
{
// Setup the ECCP for PWM in full bridge mode.
setup_ccp1(CCP_PWM_FULL_BRIDGE | CCP_PWM_H_H);
set_tris_c(0xC3); // Set pins C2-C5 as outputs

setup_timer_2(T2_DIV_BY_1, 255, 1);

set_pwm1_duty(75);

while(1);
}
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