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

Problem with PWM

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








PostPosted: Tue Nov 18, 2008 2:58 pm     Reply with quote

Hi ! I'm newcomer . May I have a question ?
My problem is "PWM resolutions".I don't know about it .
Would you please help me ?
Thanks very much!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 18, 2008 3:08 pm     Reply with quote

Here's a Piclist article that shows the maximum PWM resolution in bits
based upon the PIC's oscillator frequency:
http://techref.massmind.org/techref/microchip/pwmrescalc.htm

If your question is about selecting 8 or 10-bit resolution with the
CCS compiler, here are some threads that explain it:
http://www.ccsinfo.com/forum/viewtopic.php?t=26751
http://www.ccsinfo.com/forum/viewtopic.php?t=24055
http://www.ccsinfo.com/forum/viewtopic.php?t=22119
http://www.ccsinfo.com/forum/viewtopic.php?t=9927
dientudong



Joined: 18 Nov 2008
Posts: 2

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 2:49 am     Reply with quote

Code:
#include "E:\BAIBAOCAONHOM7\New Folder\taolao.c.h"
#include<16F877A.h>
unsigned char num[8]={0x00,0x15,0x21,0x31,0x48,0x50,0x64,0x78};
unsigned char j ;
void main()
  {
      set_tris_c(0);
      while(1)
       {
          for(j=0;j<8;j++)
           {
             PORTC=num[j];
              delay_ms(1);
           }
       }
  }

My problem is "error in PORTC". Would you please help me ?


Split thread into new topic.
-- Forum Moderator.
Ttelmah
Guest







PostPosted: Wed Nov 19, 2008 5:24 am     Reply with quote

There is nothing called 'PORTC', unless you have declared it...
If you want to write a value to the port, the CCS function, is output_c(num[j]);

This has _nothing_ to do with PWM, which this thread is about.Why post your question here?...
dientudong



Joined: 18 Nov 2008
Posts: 2

View user's profile Send private message

PostPosted: Wed Nov 19, 2008 8:20 am     Reply with quote

Code:
#include <16F877A.h>                                                            //
#use delay(clock=20000000)                                                      //
#include <lcd.c>                                                                //
float vantoc,soxung;                                                            //
int8 a,b,c,d,a1;                                                                //
int16 sovong,i;                                                                 //
///////////////////////////////////////
////////////khai bao va chuong trinh ngat cho TIMER1/////////////////////
#int_TIMER1                                                            //
void TIMER1_isr(void)                                                  //
 {                                                                     //
   soxung=get_timer0();      //get num pulses thatTimer0 counts             //
   set_timer1(65535);        // Trong 1ms                              //
   if(tmr1if==1)             //if Timer1 overflows , tmr1if =1        //
    {                                                                  //
      intcon=0;              //stop ngat (reset interrupt parameters )    //
      a1=1;                  //cho a1=1                                //
    }                                                                  //
 }                                                                     //
//////////////////////////end TIMER1///////////////////////////
//////////////////////////begin main program////////////////////////////


void main()
{
   trisa=0xFF;                        //set RA4 input,pin get pulses from Encoder
   trisb=0;                           //portC is output
   trisc=0;                           // portC is output
   trisd=0;                           // portD is output
   lcd_init();                        //ham khoi tao LCD
   lcd_gotoxy(1,1);                   //row 1 column 1
   lcd_putc("Beginning....");         // print beginning....
   delay_ms(1000);                    //  1s
   lcd_putc('\f');                    //dotpoint  flashs
   setup_timer_2(T2_DIV_BY_2,254,1);  //tao f(pwm)=9775Hz or T(pwm)=0.1023ms
   setup_ccp1(CCP_PWM);               //thiet lap chan CCP1 o che do PWM
   for(i=0;i<1000;i++)                //tu 0 den 1000 thi toc do tang dan
     {
       set_pwm1_duty(i);              // Toc do tang dan
       delay_ms(1);
       set_timer0(0);                 //lam moi Timer0 de chuan bi dem xung
       set_timer1(65535);             //dat gia tri cho Timer1_khoang 1s
       setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_1);
       setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);       
       enable_interrupts(INT_TIMER1);  //cho phep ngat Timer1
       enable_interrupts(GLOBAL);      //cho phep ngat toan cuc
       delay_ms(10);  //

       if(a1==1)   //every Timer1 interrupts, a1=1 ,then calculate vantoc
         {
           vantoc=((float)(60*soxung)/(0.01*100));    //Tinh van toc
           a=vantoc/1000;                             //chia lay phan nguyen
           b=(int)(vantoc-1000*a)/100;                //chia lay phan nguyen
           c=(int)(vantoc-1000*a-100*b)/10;           //chia lay phan nguyen
           d=(int)vantoc%10;                          //chia lay phan du
           ///////////////////toi phan hien thi LCD/////////////////////////////
           lcd_gotoxy(3,3);         //den vi tri hang 3 cot 3
           lcd_putc(a+48);          //in ra a
           lcd_gotoxy(3,4);         //den vi tri hang 3 cot 4
           lcd_putc(b+48);          //in ra b
           lcd_gotoxy(3,5);         //den vi tri hang 3 cot 5
           lcd_putc(c+48);          //in ra c
           lcd_gotoxy(3,6);         //den vi tri hang 3 cot 6
           lcd_putc(d+48);          //in ra d
           lcd_gotoxy(4,3);         //den vi tri hang 4 cot 3
           lcd_putc("vong/phut");   //in ra "vong/phut"
           lcd_gotoxy(2,2);         //den vi tri hang 2 cot 2
           lcd_putc("toc do dc");   //in ra "toc do dc"
           delay_ms(5);             //
           tmr0if=0;tmr1if=0;       //Xoa co tran cua Timer0 va Timer1
         }
     }
}

I have problem in the code. Please help me.
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