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

16f877 pwm code problem

 
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 May 09, 2010 2:17 pm     Reply with quote

Try this program. It will go from 0 to 100% duty cycle. It starts at 50%.
When you press 'F', it increases the duty cycle. When you press 'R' it
decreases the duty cycle. When you press 'S', it goes to 50%.
I tested this program in hardware with compiler vs. 4.107.
Code:

#include <16F877.h>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000) 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//===========================
void main()
{
char c;
int8 pwm_duty;

setup_ccp1(CCP_PWM);       
setup_timer_2(T2_DIV_BY_1, 49, 1);

pwm_duty = 25;   // Initially set pwm duty cycle to 50%
set_pwm1_duty(pwm_duty); 


while(1)
  {
   c = toupper(getc());   // Wait for input

   if(c == 'F')
     {
      if(pwm_duty < 50)
        {
         pwm_duty++;
         set_pwm1_duty(pwm_duty); 
        }
     }
   
   if(c == 'R')
     {
      if(pwm_duty > 0)
        {
         pwm_duty--;
         set_pwm1_duty(pwm_duty); 
        }
     }


   if(c == 'S')
     {
      pwm_duty = 25;
      set_pwm1_duty(pwm_duty); 
     }

  }
}
Neo



Joined: 06 May 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon May 10, 2010 12:28 pm     Reply with quote

Thank you PCM programmer, but i tried my code today and it worked fine ;)


But i have new question, i want to get complemented pulse on other pwm out port. How can i turn first pulse to inverse?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 10, 2010 1:07 pm     Reply with quote

The 16F877 doesn't have the ability to do that. You need to use another
type of PIC.

It would help if you tell us what is the purpose of your project.
Neo



Joined: 06 May 2010
Posts: 5

View user's profile Send private message

PostPosted: Mon May 10, 2010 1:40 pm     Reply with quote

I'm trying to make boost converter with Mosfet, and this control circuit dirves mosfet at 100kHz.

I asked that inverted pulse for my friend, he tries static compensation and need to drive 2 mosfets with complemented pwm.
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