View previous topic :: View next topic |
Author |
Message |
theasus
Joined: 31 May 2009 Posts: 79
|
How can I use PWM FULL_BRIDGE? |
Posted: Wed Jul 01, 2009 9:31 am |
|
|
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
|
|
|
theasus
Joined: 31 May 2009 Posts: 79
|
|
Posted: Thu Jul 02, 2009 12:09 am |
|
|
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
|
|
Posted: Thu Jul 02, 2009 12:36 am |
|
|
1. Post your compiler version.
2. How do you know for certain that Proteus simulates it properly ? |
|
|
theasus
Joined: 31 May 2009 Posts: 79
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 02, 2009 11:11 am |
|
|
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
|
|
Posted: Thu Jul 02, 2009 1:03 pm |
|
|
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
|
|
Posted: Thu Jul 02, 2009 1:35 pm |
|
|
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
|
|
Posted: Fri Jul 03, 2009 12:34 am |
|
|
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
|
|
Posted: Sun Jul 05, 2009 4:30 pm |
|
|
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);
} |
|
|
|
|