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

Help with PWM on dsPIC 30f2010
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
briantlam



Joined: 03 Oct 2007
Posts: 4

View user's profile Send private message

Help with PWM on dsPIC 30f2010
PostPosted: Wed Oct 03, 2007 5:05 pm     Reply with quote

I am relatively new to programming microcontrollers. I started with the dsPIC development kit and am trying to produce a PWM. What I am trying to do is produce a PWM where the duty cycle is adjusted by the pot. I was able to setup the ADC and read the value through RS232. I've had no luck setting up the PWM.

I've tried using:

setup_capture()
set_pwm_duty()
setup_power_pwm()
setup_power_pwm_pins()
set_power_pwm_duty()

but the complier doesn't seem to recognize these functions. I'm not sure if I'm missing header files or something else. Any help will be greatly appreciated. Working sample code will be appreciated even more.

Thanks.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Oct 03, 2007 5:33 pm     Reply with quote

See the Ex_PWM.c example file. It's in this directory:
Quote:
c:\program files\picc\examples\ex_pwm.c


See this thread for a shorter version of that example code:
http://www.ccsinfo.com/forum/viewtopic.php?t=31216
briantlam



Joined: 03 Oct 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 1:43 pm     Reply with quote

I looked at that code and came up with some for my device. The code compiles but I do not get an output on the PWM pins. Here is my code:

#include <30F2010.h>
#fuses HS,NOWDT
#use delay (clock=20000000)

int16 duty=32768;

void main()
{
setup_timer3(TMR_INTERNAL);
set_pwm_duty(2,adc_reading);
setup_compare(2,COMPARE_PWM);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 2:06 pm     Reply with quote

That doesn't look like a simple PWM test program. Also, it doesn't have
a while(1) statement at the end. Without that, the PIC will go to sleep
and PWM will stop. Also, you have a variable called 'duty' but you don't
use it in the program.

Basically, you need to make a small, simple, complete PWM test program.
Don't try to use any advanced features at this time. Just get PWM running.
briantlam



Joined: 03 Oct 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 2:12 pm     Reply with quote

Sorry, I made some edits before copying over to this post. Here's the code I am using now, which still doesn't work.

#include <30F2010.h>
#fuses HS,NOWDT
#use delay (clock=20000000)

int16 duty = 32768;

void main()
{
while(TRUE)
{
setup_timer3(TMR_INTERNAL);
setup_compare(2,COMPARE_PWM);
set_pwm_duty(2,duty);
}

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 2:17 pm     Reply with quote

I didn't mean put it in a while() loop. I meant put a while(1) statement
at the end of main() by itself, to prevent the user program from hitting
the hidden sleep instruction that CCS puts there. Example:

Code:
void main()
{

// user program



while(1);
}
briantlam



Joined: 03 Oct 2007
Posts: 4

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 2:25 pm     Reply with quote

Here the new code that still doesn't work:

Code:
#include <30F2010.h>
#fuses HS,NOWDT
#use delay (clock=20000000)

int16 duty = 32768;

void main()
{
   setup_timer3(TMR_INTERNAL);     
   set_pwm_duty(2,duty);
   setup_compare(2,COMPARE_PWM);
     
   while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 04, 2007 3:44 pm     Reply with quote

I don't have the PCD compiler. I will have to download the demo to
work on this. Basically, all I can do is look at the .LST file to see if
the CCS functions are setting up the PWM module according to the
30F2010 data sheet.
ozzy_dm
Guest







pic24f
PostPosted: Sun Nov 25, 2007 12:58 pm     Reply with quote

PCM programmer wrote:
I don't have the PCD compiler. I will have to download the demo to
work on this. Basically, all I can do is look at the .LST file to see if
the CCS functions are setting up the PWM module according to the
30F2010 data sheet.



I'm with the same problem using a PIC24FJ128GA006.
It looks that the compiler doesnt give support to PWM for this device.

I looked at 24fj128ga006.h file, ando doesn't have any of those instructions there.

How can I use the PWM, in this device, using this compiler?
ozzy_dm
Guest







Re: pic24f
PostPosted: Sun Nov 25, 2007 1:04 pm     Reply with quote

ozzy_dm wrote:
PCM programmer wrote:
I don't have the PCD compiler. I will have to download the demo to
work on this. Basically, all I can do is look at the .LST file to see if
the CCS functions are setting up the PWM module according to the
30F2010 data sheet.



I'm with the same problem using a PIC24FJ128GA006.
It looks that the compiler doesnt give support to PWM for this device.

I looked at 24fj128ga006.h file, ando doesn't have any of those innstructions there.

How can I use the PWM, in this device, using this compiler?


I did forget to put my code here..

#include <24FJ128GA006.h>
#device adc=10
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=25000000)

void main()
{
int16 value;

setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_4, 63, 1);

setup_adc_ports(sAN4|VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(4);
delay_us(20);

while(1)
{
value=read_adc();
set_pwm1_duty(value);
}
}

The errors:

*** Error 12 "pwm.c" Line 10(14,15): Undefined identifier -- setup_ccp1
*** Error 12 "pwm.c" Line 11(17,18): Undefined identifier -- setup_timer_2
*** Error 12 "pwm.c" Line 21(20,21): Undefined identifier -- set_pwm1_duty
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Nov 25, 2007 2:08 pm     Reply with quote

They have substituted a new function, called "setup_compare()", but
it doesn't appear to be described in the current PCD manual.
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 25, 2007 3:12 pm     Reply with quote

I get errors trying to get a PWM from the 24FJ64GA004 micro with the PWM example.

*** Error 108 "EX_PWM.c" Line 159(48,49): Invalid parameters to built in function :: Invalid Pin

*** Error 108 "EX_PWM.c" Line 169(35,37): Invalid parameters to built in function :: Invalid Pin

This has been reported to CCS, as extracted from my email reply

Quote:
We have been able to recreate the problem here and it looks like an internal compiler issue. We will let you know when we have a fix on this.


It may be possible that these faults are related. Confused

reported in 4.062, still the same in 4.063. I would suspect maybe next release may have this fix Rolling Eyes

I should say that the earlier PWM example did not allow for the PCD 24 bit however, the the revised PWM example has added this.

Code:
#if defined(__PCB__)
#include <16C56.h>
.
.
#elif defined(__PCM__)
#include <16F877.h>
.
.
#elif defined(__PCH__)
#include <18F452.h>
.
.
#elif defined(__PCD__)
#include <30F2010.h>
.
.


At least present in the current version. I dont know when this was done, It was not in the first release of V4
_________________
What has been learnt if you make the same mistake? Wink
Guest








PostPosted: Sun Nov 25, 2007 6:46 pm     Reply with quote

PCM programmer wrote:
They have substituted a new function, called "setup_compare()", but
it doesn't appear to be described in the current PCD manual.


I tried to use setup_compare().

But didn't work... Maybe because I don't know how to use certainly. Does not have any help file with it.
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Mon Nov 26, 2007 3:05 am     Reply with quote

example in EX_PWM.c
for PCD Look at the example after the "#else"

Code:

#if !defined(__PCD__)
void main(void)
{
//8 bit coding
....
}
#else

void main(void)
{
//16 bit coding
....
setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);
  while(TRUE)
  {
    value=read_adc();
    .....
    set_pwm_duty(1,value ....);
    ....

}
#endif

}

_________________
What has been learnt if you make the same mistake? Wink
Ormiga
Guest







PostPosted: Fri Aug 29, 2008 12:11 pm     Reply with quote

Quote:

I get errors trying to get a PWM from the 24FJ64GA004 micro with the PWM example.

*** Error 108 "EX_PWM.c" Line 159(48,49): Invalid parameters to built in function :: Invalid Pin

*** Error 108 "EX_PWM.c" Line 169(35,37): Invalid parameters to built in function :: Invalid Pin


Does anyone solve this problem?

I'm trying to use the setup_compare with a 24FJ16GA002 and geting the same errors. But the same code works with DSPIC30F4013. What i'm doing wrong?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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