Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

compare mode of PIC18f4584

Status
Not open for further replies.

deepa.malagi

New Member
HI,

I am using PIC18f4585 ,I have to generate a frequencies from 23.8 to 166Hz using CCP module in compare mode. but I am not able to generate this

my code is
#include<p18f4585.h>
//_CONFIG1H = 0x09;

//#define
#pragma config OSC = IRCIO7
//#pragma config PWRT = ON
#pragma config BOREN = OFF
#pragma config WDT = OFF
#pragma config MCLRE = ON
#pragma config PBADEN = OFF
//#pragma config CCP2MX = PORTC
#pragma config LVP = OFF
#pragma config DEBUG = ON

void pwm_configure(void);
void BIT16_PWM(void);

main(void)
{
OSCCON = 0x67;
OSCTUNE = 0x80;

TRISD = 0x00;
PORTD = 0x00;

CCP1CON = 0x00;
TMR1H = 0x00;
TMR1H = 0x00;
TRISC = 0x00;
T1CON = 0x30;
T3CON = 0x00;
PIE1bits.CCP1IE=0; // Enable Capture/Compare CCP1 interrupt
INTCONbits.PEIE=0; // Enable peripheral block interrupts
INTCONbits.GIE=0; // Enable maskable interrupts as whole

CCPR1H = 0x7F;
CCPR1L = 0xFF;

CCP1CON = 0x02;

T1CON |= 0x01;

//BIT16_PWM();
//pwm_configure();
while(1);
}

void pwm_configure(void)
{
PR2 = 0x32;
ECCPR1L =(unsigned char)(PR2*0.75);
//CCPR1L =(unsigned char)(PR2*0.05);
TRISD = 0x00;
TRISC = 0X00;
TMR2 = 0x00; // LOAD 8 BIT VALUE IN TMR2 00 to FF =>256 steps
T2CON = 0x04; // TIMER ON ,postscaler OFF ,prescaler OFF
//CCP1CON = 0x0C;
ECCP1CON = 0x0C; // PWM MODULE ON
//CCP1CON |= 0x20;

}
void BIT16_PWM(void)
{
CCP1CON = 0x00;
TMR1H = 0x00;
TMR1H = 0x00;
TRISC = 0x00;
T1CON = 0x30;
T3CON = 0x00;

CCPR1H = 0x7F;
CCPR1L = 0xFF;

CCP1CON = 0x02;

T1CON |= 0x01;
PIE1bits.CCP1IE=0; // Enable Capture/Compare CCP1 interrupt
INTCONbits.PEIE=0; // Enable peripheral block interrupts
INTCONbits.GIE=0; // Enable maskable interrupts as whole

please anybody help me to do so.

If possible give me a sample code for CCP module in compare mode, and also how to calculate CCPR1 values .
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top