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

PWM problem

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PWM problem
PostPosted: Sat Oct 31, 2009 5:13 am     Reply with quote

Hi

I will try make a little program to test pwm, but I don't know some things...

How I know my range values of pwm? Is it 0-255, 0-512 or 0-1024 ?

How I can determine this?

My program:
Code:

#include <18F252.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,BROWNOUT,STVREN
#use delay(clock=20000000)
#use rs232(baud=115200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#build(reset=0x200)
#build(interrupt=0x208)
#org 0x0000,0x01ff
void bootloader() {
#asm
  nop
#endasm
} // Reserve space for the bootloader

long inc = 0;

#int_rda
void rda_isr(void)
{
char c;
c=getc();

switch(c)
   {
   case '+':   
            inc=inc+20;
            break;
   case '-':   
            inc=inc-20;
            break;
   }
}

void main ()
{
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);     
   setup_timer_2(T2_DIV_BY_1, 255, 1);
   setup_ccp1(CCP_PWM);
   set_pwm1_duty(inc); 
   
while(TRUE)
{
   if ((inc>=0) || (inc<=255))   
      {
      printf("\rLuminosidade:%3lu",inc);
      set_pwm1_duty(inc);
      }
   
   if (inc<0) printf("\rLuminosidade:---");
   if (inc>250) printf("\rLuminosidade:+++");
}
}

Someone can help me?

Best regards
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Thu Nov 26, 2009 3:20 pm     Reply with quote

hi

To not open other post I edit this... because on older have a stupid question...
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Thu Nov 26, 2009 4:26 pm     Reply with quote

Take datasheet of your PIC and look at PWM section. There is a formula which is used to calculate width of PWM. Wink

There is also the formula from which you can calculate the frequency. Wink
filjoa



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

PostPosted: Fri Nov 27, 2009 5:45 am     Reply with quote

Hi

I read the datasheet and say there 8bits and 10bits... because that my confusion... but it solve, my PWM is 10bits Wink thanks.
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