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.

Software PWM on pic 18f

Status
Not open for further replies.

8051

Newbie level 3
Joined
Aug 27, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
South Africa
Activity points
1,304
Can anyone give me some advice on how to generate an additional pwm output with the pic18f4520.
I see that it is possible to do so but all I can find is examples in assembler and I only know C
 

If you are using timer 2 for the timebase of your other pwm outputs,
you can use the timer 2 interrupt to generate a pwm.
For example.

Code:
#define PUMP_PERIOD 100

volatile unsigned char pump_pwm_mark;

//set pwm width

pump_pwm_mark = 50;

/*--- Output  pwm ---*/

interrupt function()
  {
  static unsigned char period = 0U;
    
  period++;
  period = period > PUMP_PERIOD ? 0U : period;
  
  if(period < pump_pwm_mark){
    PWM_OUT = 1;
    }
  else{
    PWM_OUT = 0;
    } 
    
  /* Clear interrupt flag */
  }
 
  • Like
Reactions: 8051

    8051

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top