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 CCS Technical Support

Simple PWM with ECCP in D7 PIN

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



Joined: 29 Sep 2010
Posts: 73
Location: Brazil

View user's profile Send private message MSN Messenger

Simple PWM with ECCP in D7 PIN
PostPosted: Sat Dec 29, 2012 9:38 am     Reply with quote

Hi guys, I am tring to learn how to use the ECCP module with the PIC 18F45K20.

I was able to configure it to show me a singnal on the CCP1 (P1A) with the code:

Code:
#include <18F45K20.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection

#use delay (clock=4000000)

void main ()

   setup_timer_2(T2_DIV_BY_16,207,1);
   setup_ccp1(CCP_PWM_HALF_BRIDGE|CCP_PWM_H_H);

   set_pwm1_duty(416L); //Should be 50% duty cycle
   
   while (true);
}


I need this signal on pin D7 (P1D). Is it possible to run the signal only on that pin?

Version: 4.114 and 4.057

thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Sat Dec 29, 2012 12:20 pm     Reply with quote

You don't want half bridge mode.
Just start with the single PWM mode (CCP_PWM).
This then defaults to P1A.
You then have to change the pulse steering register to direct this output to P1D (CCP_PULSE_STEERING_D).
So:
Code:

#include <18F45K20.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES XT                       //Crystal osc <= 4mhz
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection

#use delay (clock=4000000)

void main ()
{
   setup_timer_2(T2_DIV_BY_16,207,1);
   setup_ccp1(CCP_PWM|CCP_PULSE_STEERING_D);
   //on some compiler versions you may need to set TRIS here
   output_drive(PIN_D7);

   set_pwm1_duty(416L); //Should be 50% duty cycle
   
   while (true);
}   


Should work with 4.114 (would _not_ trust 4.057 - this was before V4 started to really work).

Best Wishes
matheuslps



Joined: 29 Sep 2010
Posts: 73
Location: Brazil

View user's profile Send private message MSN Messenger

PostPosted: Sat Dec 29, 2012 5:10 pm     Reply with quote

Thanks man, working like a charm!
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