Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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
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: 109
  • CE372_Demo.zip
    6.2 KB · Views: 89
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);
   }

}
 

Ooh.... thats really great... All the best.

regards,
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top