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

CCP4 PWM 18F66J60

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



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

CCP4 PWM 18F66J60
PostPosted: Thu May 14, 2009 3:38 am     Reply with quote

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 Sad .

Do you have any idea?

Thanks,
Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 14, 2009 11:40 am     Reply with quote

Post your compiler version.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Thu May 14, 2009 12:19 pm     Reply with quote

Compiler version : PCD 4.083

Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 14, 2009 12:27 pm     Reply with quote

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.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Thu May 14, 2009 1:04 pm     Reply with quote

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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 14, 2009 1:10 pm     Reply with quote

Quote:
PIN_LED_SYNC = OFF;

Post the #define statement for 'OFF' so I can compile the program.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Thu May 14, 2009 2:39 pm     Reply with quote

#define OFF 0
Thanks,
Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 14, 2009 3:09 pm     Reply with quote

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);
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Thu May 14, 2009 3:45 pm     Reply with quote

Thanks for your help Very Happy !!!
I'll try that on Monday.

Franck.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Mon May 25, 2009 12:26 pm     Reply with quote

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.
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Mon May 25, 2009 12:50 pm     Reply with quote

Same problem on another design, with the same micro.
The problem is not hardware...

Franck.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 25, 2009 1:42 pm     Reply with quote

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);
}
Franck26



Joined: 29 Dec 2007
Posts: 122
Location: Ireland

View user's profile Send private message

PostPosted: Tue May 26, 2009 12:13 pm     Reply with quote

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.
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