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

PWM with PIC16F88

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







PWM with PIC16F88
PostPosted: Fri Jul 17, 2009 7:02 pm     Reply with quote

I’m trying to use the RB3 pin for CCP1 with a 16F88. In order to do this I use “set_pwm2_duty” but it says it’s an Undefined Identifier. It works when I use “set_pwm1_duty” which ,I suppose, sets the duty cycle in pin RB0.
I put the code below.
I would appreciate if someone helps me with that.
Thanks
Code:
Code:
#include <16F88.h>
 
#DEVICE ADC = 10           
#USE DELAY(CLOCK = 4000000) 
#include "fuses16F88.c"     
#include "math.h"           
#include <lcd.c>                 

#BYTE TRISA = 0X85
#BYTE TRISB = 0X86
#BYTE PORTA = 0X05
#BYTE PORTB = 0X06
#BYTE CONFIG1 = 0X2007

void main(void)
{
float valor, duty;
disable_interrupts(GLOBAL);     
PORT_B_PULLUPS(FALSE);           

//Config PWM

bit_clear(CONFIG1,12);             
setup_ccp1(CCP_PWM);             
setup_timer_2(T2_DIV_BY_1, 225, 1);   
TRISB = 0b00;                       
//set_pwm1_duty(0);         

//Config ADC

setup_adc(ADC_CLOCK_INTERNAL|VSS_VDD);     
setup_adc_ports(sAN0);                     
TRISA = 0xFF;                               
set_adc_channel(0);                   
lcd_init();           

while(true)
   {
 
   delay_us(20);
   valor = read_adc();
   duty = (225.0/1024.0)*(valor);
   set_pwm2_duty(duty);             
   
   lcd_putc('\f');               
   lcd_gotoxy(1,1);
   printf(lcd_putc,"%f", valor);
   lcd_gotoxy(1,1);
   delay_ms(100);   
  }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jul 17, 2009 7:56 pm     Reply with quote

Quote:
In order to do this I use “set_pwm2_duty” but it says it’s an Undefined Identifier

Download the 16F88 data sheet. At the bottom of the first page, it lists
the number of CCP modules in the PIC.
http://ww1.microchip.com/downloads/en/DeviceDoc/30487c.pdf
set_pwm2_duty() is only available if there are 2 or more CCP modules.

To select the pin that is used by CCP1, you need to use one of the
following values in bold in your #fuses statement:
Quote:
// Fuses: LP,XT,HS,EC_IO,NOWDT,WDT,NOPUT,PUT,MCLR,NOMCLR,BROWNOUT
// Fuses: NOBROWNOUT,LVP,NOLVP,CPD,NOCPD,WRT,NOWRT,DEBUG,NODEBUG,CCPB0
// Fuses: CCPB3,PROTECT,NOPROTECT,INTRC,INTRC_IO,RC,RC_IO,FCMEN
// Fuses: NOFCMEN,IESO,NOIESO
reader
Guest







PostPosted: Fri Jul 17, 2009 8:21 pm     Reply with quote

Thanks to you.
Now is working perfectly.
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