Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

CCP module programming in PIC16f877a

Status
Not open for further replies.

pradipmagar001@gmail.com

Newbie level 4
Newbie level 4
Joined
Jul 25, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
India
Activity points
1,382
In pic16f877a 10bit adc is there. I have configured CCP module for PWM operation. I am facing the problem that
CCPRL is 8bit register and adc result is 10bit and it is in two registers ADRESH and ADRESL. I have taken it in single variable by using following method-
adcval=(ADRESH<<8)|ADRESL;

but now problem is that how to load this 10 bit value in 8-bit CCPRL register as a new timebase?.
please help..
this code is running very good for pic16f72(8 bit adc).
 

The pwm also has ten bit resolution.
Quote from data sheet:

The PWM duty cycle is specified by writing to the
CCPR1L register and to the CCP1CON<5:4> bits. Up
to 10-bit resolution is available. The CCPR1L contains
the eight MSbs and the CCP1CON<5:4> contains the
two LSbs. This 10-bit value is represented by
CCPR1L:CCP1CON<5:4>.

Code:
/*--- Set Duty Cycle ---*/

void set_duty_cycle(unsigned int dc)
  {
  unsigned char lsb;

  if(dc > MAXDUTY){
    dc = MAXDUTY;
    }

  lsb = dc & 0x0003;
  CCP1CON &= 0xcf;
  CCP1CON |= (lsb << 4);  
  CCPR1L = (dc >> 2);
  }
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top