Sample code for PIC24FJ16GA002 with pwm 4 channels using CCS C complier (PCWHD)

Status
Not open for further replies.

Prakasit Man

Newbie level 4
Joined
Jul 18, 2013
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Bang Yai, Nonthaburi, Thailand, Thailand
Visit site
Activity points
40
Hello All kind experts,

I am a newbie for PIC24F series. :---(

Does anyone can give me the sample code for the application as mentioned on thread subject? I want to have the PWM period about 10 kHz approximately. I planned to use the internal RC oscillator. Machine frequency is 8MHz. below is my starting code but the rest I need your help. These 4 PWMs will use to drive 4 motors. Thanks in advance.

Code:
#include <24FJ16GA002.h>
#FUSES FRC,NOWDT
#FUSES ICSP1      
#FUSES NOIOL1WAY    //Allows multiple reconfigurations of peripheral pins
#FUSES OSCIO        //OSC2 is general purpose output
#FUSES NOPR         //Pimary oscillator disabled
#USE delay(clock=8000000,internal)

void main (void)
{
              // Disturb you to help me to create PWM //
}
 

Hello there,

Try these attachments . It might be helpful for you.

Best regards,
 

Attachments

  • CE366-VCO using ADC and PWM.zip
    48.6 KB · Views: 138
  • CE372_Demo.zip
    6.2 KB · Views: 118
Hi Jinzpaul4u

Thanks for your advise. This helps me a lot. Here is my worked code.

Code:
#include <24FJ16GA002.h>
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOJTAG                   //JTAG disabled
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled

#device ICSP=1
#use delay(internal=8MHz)
#pin_select OC1=PIN_B5  // PWM1 out  

void main()
{

   setup_timer2(TMR_INTERNAL | TMR_DIV_BY_1, 39999);

   setup_compare(1, COMPARE_PWM | COMPARE_TIMER2);


   while(TRUE)
   {
         set_pwm_duty(1, 19999);
   }

}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…