View previous topic :: View next topic |
Author |
Message |
briantlam
Joined: 03 Oct 2007 Posts: 4
|
Help with PWM on dsPIC 30f2010 |
Posted: Wed Oct 03, 2007 5:05 pm |
|
|
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
|
|
|
briantlam
Joined: 03 Oct 2007 Posts: 4
|
|
Posted: Thu Oct 04, 2007 1:43 pm |
|
|
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
|
|
Posted: Thu Oct 04, 2007 2:06 pm |
|
|
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
|
|
Posted: Thu Oct 04, 2007 2:12 pm |
|
|
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
|
|
Posted: Thu Oct 04, 2007 2:17 pm |
|
|
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
|
|
Posted: Thu Oct 04, 2007 2:25 pm |
|
|
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
|
|
Posted: Thu Oct 04, 2007 3:44 pm |
|
|
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 |
Posted: Sun Nov 25, 2007 12:58 pm |
|
|
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 |
Posted: Sun Nov 25, 2007 1:04 pm |
|
|
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
|
|
Posted: Sun Nov 25, 2007 2:08 pm |
|
|
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
|
|
Posted: Sun Nov 25, 2007 3:12 pm |
|
|
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.
reported in 4.062, still the same in 4.063. I would suspect maybe next release may have this fix
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? |
|
|
Guest
|
|
Posted: Sun Nov 25, 2007 6:46 pm |
|
|
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
|
|
Posted: Mon Nov 26, 2007 3:05 am |
|
|
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? |
|
|
Ormiga Guest
|
|
Posted: Fri Aug 29, 2008 12:11 pm |
|
|
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? |
|
|
|