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

CCS Power PWM functions on 18F1330 not work

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



Joined: 06 Mar 2007
Posts: 3

View user's profile Send private message

CCS Power PWM functions on 18F1330 not work
PostPosted: Tue Mar 06, 2007 3:51 am     Reply with quote

I have tried to use CCS power PWM functions on 18F1330 with no success. There is no output at all from I/O pins. Please see the attached code.

Thank you.

Code:

#include <18f1330.h>

#fuses HS,NOWDT,NOMCLR
#use delay(clock=20000000)

void main(void)
{

   unsigned int16 j,dutyr=0,dutyg=0,dutyb=0;

   setup_power_pwm_pins(PWM_ODD_ON,PWM_ODD_ON,PWM_ODD_ON,PWM_ODD_ON);
   setup_power_pwm(PWM_CLOCK_DIV_4|PWM_FREE_RUN,1,0,4095,0,1,0);

   while(1) {

      for(j=0;j<256;j++){
         dutyr=255-j;
         dutyg=j;
         dutyb=0;
         set_power_pwm0_duty(dutyr*16);
         set_power_pwm2_duty(dutyg*16);
         set_power_pwm4_duty(dutyb*16);
         delay_ms(10);
      }

      for(j=0;j<256;j++){
         dutyr=0;
         dutyg=255-j;
         dutyb=j;
         set_power_pwm0_duty(dutyr*16);
         set_power_pwm2_duty(dutyg*16);
         set_power_pwm4_duty(dutyb*16);
         delay_ms(10);
      }

      for(j=0;j<256;j++){
         dutyr=j;
         dutyg=0;
         dutyb=255-j;
         set_power_pwm0_duty(dutyr*16);
         set_power_pwm2_duty(dutyg*16);
         set_power_pwm4_duty(dutyb*16);
         delay_ms(10);
      }

   }

}
Ttelmah
Guest







PostPosted: Tue Mar 06, 2007 8:22 am     Reply with quote

A couple of thoughts. Have you looked at the fuse 'NOPWMPIN'?. What is connected to the '/FLTI' input?.

Best Wishes
RiVAFlow
Guest







same here
PostPosted: Wed Jun 03, 2009 4:30 pm     Reply with quote

I have the same problem with that pic. I can't get to work the power_pwm with the ccs, even with the NOPWMPIN, and taking care of the FLTA input.
Any help?
I think it needs a new library.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 03, 2009 4:52 pm     Reply with quote

Post your test program and your compiler version.

Make the test program be a lot more simple than the earlier one in
this thread. He's attempting to change the duty cycle in a loop, and
he hasn't even got it working with a constant duty cycle yet. That's
not how to do it.

Here's an example of a more simple test program for power pwm:
http://www.ccsinfo.com/forum/viewtopic.php?t=37206

Remember to post your compiler version.
Ttelmah
Guest







PostPosted: Thu Jun 04, 2009 2:56 am     Reply with quote

One more comment. You must not have a selection for a fourth module on the 1330. It doesn't have a fourth module present. Change the last output pin setup to 'PWM_OFF'.

Best Wishes
loem



Joined: 06 Mar 2007
Posts: 3

View user's profile Send private message

PostPosted: Sun Aug 16, 2009 3:42 am     Reply with quote

I use v3.249 without success. Finally, I have to directly setup
PWM registers in order to use PWM pins on 18F1330.

Now, PWM pins work. However, I got another problem.
It seems that v3.249 doesn't have the proper startup code
for 18F1330. Besides Tx, Rx, PWM1, PWM3, PWM5, OSC1,
and OSC2, all IO pins are used as input from DIPSW including
MCLR. I have already use NOMCLR fuse.

Any suggestion ?
Guest








PostPosted: Sun Aug 16, 2009 8:06 am     Reply with quote

please would you give to us sample code for 18f1330 or 1230
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Aug 16, 2009 1:54 pm     Reply with quote

Quote:
please would you give to us sample code for 18f1330 or 1230

I don't have either of those two PICs to test in hardware, but the following
program might work. The 18F1330 doesn't have the two ordinary PWM
channels that the 18F4431 has. Also, it only has 3 Power PWM channels
instead of the 4 channels that the 18F4431 has. So, I just removed the
lines of code that are not supported in the 18F1330 to create the program
below. Note that the setup_power_pwm_pins() function requires 4
parameters, even though the 18F1330 only supports 3 channels. But
that's not a problem. Try this program and see if it works. If it doesn't,
then post your compiler version.
Code:

#include<18F1330.h>
#fuses INTRC_IO, NOWDT, NOPROTECT, NOBROWNOUT, PUT 
#use delay(clock=8000000)

#define POWER_PWM_PERIOD 1999  // 1 KHz pwm freq with 8 MHz osc.

//=======================================
void main()
{

// Setup the 4 Power PWM channels as ordinary pwm channels.
setup_power_pwm_pins(PWM_ODD_ON, PWM_ODD_ON, PWM_ODD_ON, PWM_ODD_ON);

// Mode = Free Run 
// Postscale = 1   (1-16) Timebase output postscaler
// TimeBase = 0   (0-65355) Initial value of PWM Timebase
// Period = 2000  (0-4095) Max value of PWM TimeBase
// Compare = 0     (Timebase value for special event trigger)
// Compare Postscale = 1 (Postscaler for Compare value)
// Dead Time

setup_power_pwm(PWM_FREE_RUN, 1, 0, POWER_PWM_PERIOD, 0, 1,0); 

set_power_pwm0_duty((int16)((POWER_PWM_PERIOD *4) * .1)); // 10%
set_power_pwm2_duty((int16)((POWER_PWM_PERIOD *4) * .4)); // 40%
set_power_pwm4_duty((int16)((POWER_PWM_PERIOD *4) * .6)); // 60%

while(1);
}
hisham.i



Joined: 22 Aug 2010
Posts: 43

View user's profile Send private message

PostPosted: Wed Oct 27, 2010 1:41 pm     Reply with quote

It is an old post, but i want to ask about the duty calculation.
why we multiply the pwm_period by 4?
mcr1981



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

PostPosted: Wed Oct 27, 2010 2:31 pm     Reply with quote

hisham.i wrote:
It is an old post, but i want to ask about the duty calculation.
why we multiply the pwm_period by 4?



To make use of the full 10 bit resolution, that's why they are forcing the 16 bit convesion. Maybe I'm wrong but I think that's why.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 27, 2010 2:59 pm     Reply with quote

Download the 18F1330 data sheet.
http://ww1.microchip.com/downloads/en/DeviceDoc/39758D.pdf
Look in this section. In a gray box on the right side, it says:
Quote:

14.6 PWM Duty Cycle

Note:
To get the correct PWM duty cycle, always
multiply the calculated PWM duty cycle
value by four
before writing it to the PWM
Duty Cycle registers. This is due to the two
additional LSBs in the PWM Duty Cycle
registers which are compared against the
internal Q clock for the PWM duty cycle
match.

Always download the PIC data sheet and read the section on the
peripheral module that you want to use.
hisham.i



Joined: 22 Aug 2010
Posts: 43

View user's profile Send private message

PostPosted: Mon Nov 01, 2010 12:54 am     Reply with quote

is it applied also to pic18f2331?
mcr1981



Joined: 27 Oct 2010
Posts: 28

View user's profile Send private message

PostPosted: Mon Nov 01, 2010 10:35 am     Reply with quote

hisham.i wrote:
is it applied also to pic18f2331?



To every PIC micro that has the 2 lsb in the middle of the CCPxCON.

You can discard those two bits and "play with an 8 bit PWM", only modify CCPxRL.
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