View previous topic :: View next topic |
Author |
Message |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
CCP4 PWM 18F66J60 |
Posted: Thu May 14, 2009 3:38 am |
|
|
Hello,
I've got some difficulty to have a PWM signal on CCP4 (RD2).
I've already had a look at this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=30035&highlight=ccp4
Code:
Code: | void main(void)
{
ClearWatchDog();
setup_adc_ports(NO_ANALOGS);
LED_PinInit(); // RD2 is an output.
setup_timer_2(T2_DIV_BY_1, 255, 1);
setup_ccp4(CCP_PWM);
set_pwm4_duty(128); // 50% duty cycle
while(TRUE)
{
ClearWatchDog();
}
} |
Fuse:
Code: | #device PIC18F66J60
#device ICD=TRUE
#FUSES DEBUG // Debug mode for use with ICD.
#FUSES NOWDT // No Watch Dog Timer
#FUSES WDT16
#FUSES NOPROTECT // Code not protected from reading
#FUSES HS // High Speed Oscillator
#FUSES NOIESO // Internal external Switch Over mode diasabled
#FUSES NOFCMEN // Fail-Safe clock disabled
#FUSES PRIMARY // Primary clock is system clock when scs=00
#FUSES ETHLED // Ethernet LED enabled
#FUSES STVREN // Stack full/underflow will cause reset
#FUSES IESO // Internal External Switch Over mode enabled
#FUSES FCMEN // Fail-safe clock monitor enabled
#FUSES NOXINST // Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#use delay(clock=25M) |
CCP4 (RD2) output is going low (due to pin init) but it stay low .
Do you have any idea?
Thanks,
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 14, 2009 11:40 am |
|
|
Post your compiler version. |
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Thu May 14, 2009 12:19 pm |
|
|
Compiler version : PCD 4.083
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 14, 2009 12:27 pm |
|
|
Quote: | ClearWatchDog();
LED_PinInit(); // RD2 is an output. |
Post those two functions, and all variable declarations used by them.
I need to be able to compile your test program. |
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Thu May 14, 2009 1:04 pm |
|
|
Code: |
typedef struct
{
unsigned int b0:1;
unsigned int b1:1;
unsigned int b2:1;
unsigned int b3:1;
unsigned int b4:1;
unsigned int b5:1;
unsigned int b6:1;
unsigned int b7:1;
}_Def_SFR_8;
volatile _Def_SFR_8 PORTD_TRIS;
volatile _Def_SFR_8 PORTD_LAT;
volatile _Def_SFR_8 PORTD_DATA;
#byte PORTD_TRIS = 0x0F95 //@0x0F95
#byte PORTD_LAT = 0x0F8C //@0x0F8C
#byte PORTD_DATA = 0x0F83 //@0x0F83
#define ClearWatchDog() #asm CLRWDT #endasm
#define PIN_DIR_OUT 0
#define PIN_LED_SYNC PORTD_LAT.b2
#define DIR_LED_SYNC PORTD_TRIS.b2
void LED_PinInit(void)
{
// Init pin.
PIN_LED_SYNC = OFF;
DIR_LED_SYNC = PIN_DIR_OUT;
}
|
Sorry, I know it looks overcomplicated to set a pin as output, it's just to keep a minimum of compatibility with other compiler...
The pin is correctly set as output, I can see that cos there is a pull-up connected and the voltage goes to 0 after init.
Thanks,
Franck.
PS: I won't have access to the forum until Monday. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 14, 2009 1:10 pm |
|
|
Quote: | PIN_LED_SYNC = OFF; |
Post the #define statement for 'OFF' so I can compile the program. |
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Thu May 14, 2009 2:39 pm |
|
|
#define OFF 0
Thanks,
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 14, 2009 3:09 pm |
|
|
The problem is in the setup_ccp4() function. It's setting pin G3 to be
an output, but it really should be setting pin D2 as an output.
It's a bug in the compiler for the 18F66J60. For the larger PICs in this
series, CCP4 is on pin G2. But for the smaller 64-pin PIC, it's on D2.
You should tell CCS about this bug. (It's still in vs. 4.092).
If you are using standard i/o mode, you can fix it by manually setting
pin D2 to be an output, and set pin G3 back as an input, as shown below:
Quote: |
setup_ccp4(CCP_PWM);
output_low(PIN_D2);
output_float(PIN_G3);
|
|
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Thu May 14, 2009 3:45 pm |
|
|
Thanks for your help !!!
I'll try that on Monday.
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Mon May 25, 2009 12:26 pm |
|
|
Hi,
Sorry for the delay, I didn't get a chance to test those lines until now.
So I've tried:
Code: | setup_ccp4(CCP_PWM);
output_low(PIN_D2);
//output_float(PIN_G3); |
I had to remove output_float(PIN_G3) due to a compilation error (normal G3 doesn't exist on the 18F66J60).
Unfortunately, it doesn't change anything: the pin D2 is going low and stay in this state....
I'm going to try on another design to see if it's hardware...
Any other idea?
Thanks,
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Mon May 25, 2009 12:50 pm |
|
|
Same problem on another design, with the same micro.
The problem is not hardware...
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon May 25, 2009 1:42 pm |
|
|
Your test program is too complicated. Try a very simple program:
Code: | #include <18F66J60.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=25M)
//================================
void main()
{
setup_timer_2(T2_DIV_BY_1, 255, 1);
setup_ccp4(CCP_PWM);
output_low(PIN_D2); // Fix for bug in compiler
set_pwm4_duty(128); // 50% duty cycle
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Franck26
Joined: 29 Dec 2007 Posts: 122 Location: Ireland
|
|
Posted: Tue May 26, 2009 12:13 pm |
|
|
Thanks PCM,
It works, the problem was that after you told me to set manually pin D2 as output, I forgot to set the duty cycle (set_pwm4_duty(128))...
Thanks again,
Franck. |
|
![](templates/subSilver/images/spacer.gif) |
|