|
|
View previous topic :: View next topic |
Author |
Message |
reader Guest
|
PWM with PIC16F88 |
Posted: Fri Jul 17, 2009 7:02 pm |
|
|
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
|
|
Posted: Fri Jul 17, 2009 7:56 pm |
|
|
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
|
|
Posted: Fri Jul 17, 2009 8:21 pm |
|
|
Thanks to you.
Now is working perfectly. |
|
|
|
|
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
|