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 CCS Technical Support

PWM CCP1 on PIC16F819

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







PWM CCP1 on PIC16F819
PostPosted: Wed Mar 05, 2003 9:36 am     Reply with quote

Hello,

In the past I used the PIC16F873 with the following (simplified) programm, which is running correctly at this device. At this case I used an external RC:

#include <16F873.h>

void main(){
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,255,1);

while(true){
set_pwm1_duty(220)
}

}


Now I have converted this programm for the
16F819, which I run with the INTRC (RA6 is CLKOUT):

#include <16F819.h>

void main(){
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1,255,1);

while(true){
set_pwm1_duty(220)
}

}

The Clock ist correctly working, but there's
no PWM-Signal on RB2 (CCP1). What I'm doing wrong?

Thanks for your replies
___________________________
This message was ported from CCS's old forum
Original Post ID: 12378
Charlie U
Guest







Re: PWM CCP1 on PIC16F819
PostPosted: Wed Mar 05, 2003 2:44 pm     Reply with quote

:=Hello,
:=
:=In the past I used the PIC16F873 with the following (simplified) programm, which is running correctly at this device. At this case I used an external RC:
:=
:=#include <16F873.h>
:=
:=void main(){
:= setup_ccp1(CCP_PWM);
:= setup_timer_2(T2_DIV_BY_1,255,1);
:=
:= while(true){
:= set_pwm1_duty(220)
:= }
:=
:=}
:=
:=
:=Now I have converted this programm for the
:=16F819, which I run with the INTRC (RA6 is CLKOUT):
:=
:=#include <16F819.h>
:=
:=void main(){
:= setup_ccp1(CCP_PWM);
:= setup_timer_2(T2_DIV_BY_1,255,1);
:=
:= while(true){
:= set_pwm1_duty(220)
:= }
:=
:=}
:=
:=The Clock ist correctly working, but there's
:=no PWM-Signal on RB2 (CCP1). What I'm doing wrong?
:=
:=Thanks for your replies

I checked the data sheet for this part, and CCP1 can be switched from RB2 to RB3 with a fuse. I'm not certain what the default is, but I usually declare all fuses for the state I want them in and not rely on the defaults, such as NOLVP if I don't want low voltage programming and WDT if I want the watch dog. If you haven't already, update the fuse statement to include CCPB2 which will force CPP1 to RB2. Also check other new features of the 819 against the defaults for the 873.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12388
Samuel Schultz
Guest







Re: PWM CCP1 on PIC16F819
PostPosted: Thu Mar 06, 2003 12:53 am     Reply with quote

Of course I've already done this. I've made the fuse settings
directly in the MPLAB IDE - CCP is correctly set to RB2, also the Watchdog, Brownout, etc. ist declared correctly, but it's still not working.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12412
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: PWM CCP1 on PIC16F819
PostPosted: Thu Mar 06, 2003 1:22 pm     Reply with quote

:=Of course I've already done this. I've made the fuse settings
:=directly in the MPLAB IDE - CCP is correctly set to RB2, also the Watchdog, Brownout, etc. ist declared correctly, but it's still not working.
------------------------------------------------------------

I think the problem is that CCS has not really implemented
the 16F819. They just added a .h file, but didn't properly
create a new device table for the chip. They're still using
register addresses for the 16F877, apparently.

Here's part of the .LST file for your test program.
This was compiled with PCM vs. 3.147.
<PRE>

This is the standard start-up code they use for most chips.
They clear the upper 3 bits of the Status register, and
they move 0x07 to the ADCON register, which sets all
analog pins to be digital. This code looks OK.
0004 0184 00234 CLRF 04
0005 301F 00235 MOVLW 1F
0006 0583 00236 ANDWF 03,F
0007 3007 00237 MOVLW 07
0008 1683 00238 BSF 03.5
0009 009F 00239 MOVWF 1F
000A 1283 00240 BCF 03.5
<BR>
Here, they are setting up the CCP. They clear bit 2
of register 0x87 (TRIS_C), and also clear bit 2 of
register 0x07 (PORT C).
This code would make bit 2 of Port C be an output,
and set it low. Unfortunately, it won't work because
the 16F819 doesn't have a Port C.
<BR>
Then they move 0x0C to register 0x17. That's correct.
<BR>
0000 00241 .......... setup_ccp1(CCP_PWM);
000B 1683 00242 BSF 03.5
000C 1107 00243 BCF 07.2
000D 1283 00244 BCF 03.5
000E 1107 00245 BCF 07.2
000F 300C 00246 MOVLW 0C
0010 0097 00247 MOVWF 17
<BR>
0000 00248 .... setup_timer_2(T2_DIV_BY_1,255,1);
<BR>
This first part of the code moves 0x04 into register 0x12.
This turns Timer2 on, with a pre-scaler of 1.
0011 3000 00249 MOVLW 00
0012 00F8 00250 MOVWF 78
0013 3804 00251 IORLW 04
0014 0092 00252 MOVWF 12
<BR>
They now move 0xFF into register 0x92,
which is the Timer2 Period Register. That's correct.
0015 30FF 00253 MOVLW FF
0016 1683 00254 BSF 03.5
0017 0092 00255 MOVWF 12
0018 1283 00256 BCF 03.5
<BR>
<BR>
By adding one line of code, we can fix the problem
with setup_ccp1(). We'll just turn the proper CCP
pin into an output, and set it low. I'm assuming
you're using PIN B2 for this (the chip can optionally
be set to use PIN B3).
<BR>
void main()
{
setup_ccp1(CCP_PWM);
// This line fixes the bug in setup_ccp1().
output_low(PIN_B2);
<BR>
setup_timer_2(T2_DIV_BY_1,255,1);
<BR>
while(true)
{
set_pwm1_duty(220);
}
}
</PRE>

This fix assumes you're using Standard i/o mode with
the compiler.

I'm not sure why you're continuously setting the pwm duty
cycle. I would have set it once, and then put a continuous
while(1); loop at the end of the program.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12438
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