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

pwm code on PIC24

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



Joined: 25 Jun 2004
Posts: 17
Location: Cremona (Italy)

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

pwm code on PIC24
PostPosted: Mon Nov 17, 2008 1:47 pm     Reply with quote

Hello

Ineed to use the output pin OC1 -2 -3 in PWM mode of the micro PIC24FJ128GA010.
I tried several times as shown in the code list, but it didn't work.
My compiler is PCWHD version 4.081.
Anyone can help me ?

Thanks.

Alessandro

Code:
 #include <24FJ128GA010.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOCOE                    //Device will reset into operational mode
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES WPOSTS16                 //Watch Dog Timer PostScalar 1:32768
#FUSES WPRES128                 //Watch Dog Timer PreScalar 1:128
#FUSES WINDIS                   //Watch Dog Timer in non-Window mode
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES FRC                      //Internal Fast RC Oscillator
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOPROTECT                //Code not protected from reading

#use delay(clock=8000000)


void main()
{

   setup_adc_ports(sAN5);
   setup_adc(adc_clock_internal);
   set_adc_channel(5);
   setup_compare(1,COMPARE_PWM | COMPARE_TIMER3 );
   setup_timer3(TMR_INTERNAL | TMR_DIV_BY_1,0 );
   setup_timer1(TMR_DISABLED|TMR_DIV_BY_1);
   enable_interrupts(INT_TIMER3);
   

while(1)
   {
   int value;
   int pw_val;

   value=read_adc();
   pw_val = value * 64;
   
   set_pwm_duty(1, pw_val);
   
   }   
}

_________________
Alessandro
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Nov 17, 2008 4:13 pm     Reply with quote

I think, you should preset the timer to 0xFFFF rather than 0 to see any PWM action. Also I don't see the purpose of enabling timer interrupt without defining a handler, but fortunately global interrupts are still disabled.
a.fava



Joined: 25 Jun 2004
Posts: 17
Location: Cremona (Italy)

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

pwm code
PostPosted: Tue Nov 18, 2008 2:16 pm     Reply with quote

Thank you FvM

I tried to load the timer 3 with 0xFFFF and I didn't use the timer3 interrupt as I think it's not necessary.
But it doesn't work.
Have you got any idea ?

Alessandro
_________________
Alessandro
nicotec



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

pwm
PostPosted: Wed Nov 19, 2008 5:15 am     Reply with quote

I have similar problem with pic24fj16ga002 using this code:
Code:

void main()

   #pin_select OC1=PIN_B4
   setup_compare(1,COMPARE_PWM | COMPARE_TIMER2 );
   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1);

   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);

   //set_pwm_duty(1,30000);
   output_low(PIN_B8);
   do
   {
   output_high(PIN_B6);
   delay_ms(500);
   output_low(PIN_B6);
   delay_ms(500);
   } while(true);

}

How do You think to solve the problem?
a.fava



Joined: 25 Jun 2004
Posts: 17
Location: Cremona (Italy)

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

PostPosted: Wed Nov 19, 2008 1:07 pm     Reply with quote

I thank you NICOTEC for the answer.

But the problem is that the function #pin_select...... the CIP 24FJ128GA010 there is and does not work.
For other types of microcontrollers the function #pin_select.... works and I have no problem of programming or operation.
_________________
Alessandro
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