20081112 Slider PWM control

Using Web page slider to control PWM output

Checked file: C:/MCC18/doc/periph-lib/PWM.htm#_Toc197156989 and the PIC18F4685 has PWM_V7, EPWM_V7 which impacts on the functions available..


In maindemo.c

In declares:

added #include <pwm.h> 

added in '// Initialize application specific hardware' section:

CloseEPWM1;  // set to know state on powerup so no accidents!


In CustomHTTPApp.c:

/****************************************************************************
My Custom Stuff
  ***************************************************************************/

added before first function:

#include <pwm.h>
#include <timers.h>

// sliders
static WORD slider1 = 0;

// PWM - track if PWM is on or off
static unsigned char pwmon = 0;

and in the 'GET Form Handlers' section: (building on previous exercise)

  // If it's the SLIDER updater file
 else if(!memcmppgm2ram(filename, "sliders.cgi", 11))
 {
  ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"slider1");
  if(ptr)
  {
  slider1 = atoi(ptr);
  if (slider1 == 0)
   {
   SetDCPWM1((char) 0);  // CCP1 on PIC18F4685
   ClosePWM1;

   SetDCEPWM1((char) 0); // CCP2 on PIC18F4685
   CloseEPWM1;

   CloseTimer2;
   pwmon = 0;  // We are no go
   }
  else
   {
   if (!pwmon)
    {
    // setup TMR2 for PWM, prescaler 1, postscaler 1, PR2 = 249 = 40khz with resolution of 1000, NICE!
    OpenTimer2(TIMER_INT_OFF & T2_PS_1_1 & T2_POST_1_1);
    OpenPWM1(249);  // resolution of 1000 per above note
    OpenEPWM1(249); // resolution of 1000 per above note
    pwmon = 1;  // We are go
    strcpypgm2ram((char*)LCDText, "PWM On          ");
    LCDUpdate();
    }
   SetDCPWM1(slider1 * 10);
   SetDCEPWM1(slider1 * 10);
   }
  }


Thats it and it works.