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

PIC16f877A PWM not fully on

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







PIC16f877A PWM not fully on
PostPosted: Mon Nov 13, 2006 9:20 pm     Reply with quote

You won't be able to see this well unless you have at least a 100Mhz
O-scope and 100 Mhz probes. I'm using a tek 2246.


I notice when the PR2 reg is set to 255 and 1023 in entered into the
ccpr1L/cc1con register the pwm output will go low(0v) for 50ns(20Mhz) every 51us(19.57)Khz and stay high(5v) for the rest of the duration.

Yes, I do have 2x 10nf and 2x 100nf cap right on the Vdd and Vss pins.
The supply voltage is very clean.


Here's a simple test prog.




PCWH v3.249

Pic16f877A is REV B6

It's no big deal.
Microchip's PIC's never do exactly what they're advertised to do.
I've been bitten by their erratas in the past.

Code:

#include <16f877A.h>
#include <stdlib.h>
#fuses HS,PUT,BROWNOUT
#use delay(clock=20000000)

#use fast_io(a)
#use fast_io(b)
#use fast_io(c)
#use fast_io(d)
#use fast_io(e)

void MAIN() {


 output_a(0);
 output_b(0);
 output_c(0);
 output_d(0);
 output_e(0);



 SET_TRIS_A(0);
 SET_TRIS_B(0);
 SET_TRIS_C(0);
 SET_TRIS_D(0);
 SET_TRIS_E(0);

 setup_ccp1(CCP_PWM);
 setup_ccp2(CCP_PWM);


 setup_timer_2(T2_DIV_BY_1, 255, 1); // 10 Bit 19.53Khz


 set_pwm1_duty(1023);
 set_pwm2_duty(1023);


     while(true){}


}

 


asm list:

Code:


....................  setup_ccp1(CCP_PWM);
0023:  BCF    03.5
0024:  BCF    07.2
0025:  MOVLW  0C
0026:  MOVWF  17
....................  setup_ccp2(CCP_PWM);
0027:  BCF    07.1
0028:  MOVWF  1D
....................
....................
....................  setup_timer_2(T2_DIV_BY_1, 255, 1); // 10 Bit 19.53Khz
0029:  MOVLW  00
002A:  MOVWF  78
002B:  IORLW  04
002C:  MOVWF  12
002D:  MOVLW  FF
002E:  BSF    03.5
002F:  MOVWF  12
....................
....................
.................... set_pwm1_duty(1023);
0030:  BCF    03.5
0031:  MOVWF  15
0032:  MOVF   17,W
0033:  ANDLW  CF
0034:  IORLW  30
0035:  MOVWF  17
.................... set_pwm2_duty(1023);
0036:  MOVLW  FF
0037:  MOVWF  1B
0038:  MOVF   1D,W
0039:  ANDLW  CF
003A:  IORLW  30
003B:  MOVWF  1D
Ttelmah
Guest







PostPosted: Tue Nov 14, 2006 8:27 am     Reply with quote

This is fairly normal.
If you were designing such a circuit, there is a problem with handling the 'ends' of the range. You have to make a decision, whether the reset, occurs before, or after the set in the clock cycle. The Microchip solution, is to have this configured, so a 0, does give nothing out, but this implies that at the other end of the range, a full-on, will result in one clock of low output. They have a hardware 'trap', so that if the output _exceeds_ the full-on value, the line gets permanantly turned on, but a value that _matches_ the full on count, on some chips gives a single low output cycle as you are seeing.
The same is true on quite a few other PWM chips (not just PICs). You can program round it, if a lesser PWM maximum count is acceptable, by setting timer2, to 254, and then if the required value on the pulse width is >=1020, setting the value to 1023, which then triggers the extra hardware.

Best Wishes
RA
Guest







PostPosted: Tue Nov 14, 2006 1:46 pm     Reply with quote

Yep, I thought so.
I suppose that's close enough by microchip standards.
On 18f parts it's much better
Darn those silicon propagation delays. Very Happy
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