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

3 PWM

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 21, 2007 2:56 pm     Reply with quote

You can't get 3 PWM channels with a different duty cycle for each
channel with the 18F4550. Basically, the 18F4550 has two PWM
modules available. The CCP1 module can be used to run a Half-Bridge
or Full-Bridge motor controller, and uses 4 output pins on the PIC.
The CCP2 can have a single PWM output.

Here's an example program. This program runs a full H-Bridge
on pins P1A, P1B, P1C, and P1D. It switches between running
the H-Bridge in the forward direction and then in reverse.
At the same time, the CCP2 is used to run a normal single PWM
channel on the CCP2 pin. Both PWM modules run off Timer2,
so they have the same frequency.
Code:

#include <18F4550.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#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);
   
// Setup CCP2 for PWM output on pin C1. 
setup_ccp2(CCP_PWM);
set_pwm2_duty(50);

// 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);
   delay_ms(5000);

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

}
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

3 pwm
PostPosted: Mon Jan 22, 2007 4:53 am     Reply with quote

I try to use the code you write but i have this error:
Undefined identifier CCP_PWM_FULL_BRIDGE
Undefined identifier CCP_PWM_FULL_BRIDGE
Undefined identifier CCP_PWM_FULL_BRIDGE_REV

I use the PCH compiler. How to write the code for this compiler. Please help
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

3 pwm
PostPosted: Mon Jan 22, 2007 6:17 am     Reply with quote

I use pwm with a low pass filter to generate the analog signal.I want 3 PWM because i have 3 diferend signal input.Can i managment the PWM like a Full-Bridge motor controller???????
Ttelmah
Guest







PostPosted: Mon Jan 22, 2007 8:55 am     Reply with quote

No.
Simplest solution, is probably to add an external I2C, or SSP driven PWM controller.
The chip _only has two PWM's available_. One supports up to four outputs, but these outputs will have the same frequency/width (except for a small adjustment introduced to ensure both drivers are not on at once). So though you can generate five 'signals', the available timings and widths, only give two output values supported.
Look at something like the DS1050, if you do not need a huge resolution.

Best Wishes
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

3 PWM
PostPosted: Wed Jan 24, 2007 5:47 pm     Reply with quote

Quote:

You can't get 3 PWM channels with a different duty cycle for each
channel with the 18F4550. Basically, the 18F4550 has two PWM
modules available. The CCP1 module can be used to run a Half-Bridge
or Full-Bridge motor controller, and uses 4 output pins on the PIC.
The CCP2 can have a single PWM output.

Here's an example program. This program runs a full H-Bridge
on pins P1A, P1B, P1C, and P1D. It switches between running
the H-Bridge in the forward direction and then in reverse.
At the same time, the CCP2 is used to run a normal single PWM
channel on the CCP2 pin. Both PWM modules run off Timer2,
so they have the same frequency.
Code:

#include <18F4550.h>
#fuses XT,NOWDT,BROWNOUT,PUT,NOLVP
#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);

// Setup CCP2 for PWM output on pin C1.
setup_ccp2(CCP_PWM);
set_pwm2_duty(50);

// 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);
delay_ms(5000);

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

}

Hi PCM Programmer ,
I tried to used this code but is not working. Is this all code or I must to but and other code????
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 24, 2007 5:57 pm     Reply with quote

Post your compiler version. This will be a number such as 3.191, 3.249,
or 4.023, etc. You can find it at the top of the .LST file (after a successful
compilation). The .LST file will be in your project directory.
Just post the version number. Don't post any numbers that come after it.
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

3 PWM
PostPosted: Thu Jan 25, 2007 4:34 am     Reply with quote

Compiler version is 3.187
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jan 25, 2007 1:16 pm     Reply with quote

I installed PCH 3.187 and it has no support for the 18F4550. It doesn't
have a .H file for it.
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

3 pwm
PostPosted: Thu Jan 25, 2007 1:33 pm     Reply with quote

So I can't use as example your code. Is it possible to modify to work on this compiler or is not possibility to work this code ?
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

3 pwm
PostPosted: Fri Jan 26, 2007 4:36 am     Reply with quote

Hello PCM programmer,now i have the 3.216 compiler but this code does not work
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 12:33 pm     Reply with quote

I don't have that version. The closest I have after that one is 3.230.
So I can't really help you with problems with that version.
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