Author Topic: PWM Initialization  (Read 6715 times)

Offline nicholka

  • Newbie
  • *
  • Posts: 1
    • View Profile
PWM Initialization
« on: April 09, 2009, 03:57:24 AM »
Hi,

I'm using the Olimex LPC2378-STK board and have successfully implemented some minor tasks.

The next goal was to configure a task to initialize PWMs.

The periodic function to be executed is as follows, note all the constants are defined (or added) to the LPC23XX.h file:

Code: [Select]
#define Period 0x4E40
#define MS  0x3E9
extern void fnInitializePWMs(int *ptrTaskTable)
{
  fnDebugMsg("In Initialize PWMS \n\r");
  //Configure the appropriate pins such than Pin 50,53,54,57 are PWM 3,4,5,6 respectively
  PINSEL3 |= 0x00228800;
  //PINSEL3 &= 0xFFDDBBFF;
  //Set the pins mentioned above as outputs
  //IO1DIR |= 0x06A00000;

  //PCLK for use with the PWMs is set to be 1/4 the input processor clock speed
  PCLKSEL0 |= (00 << 12);

  //Timer Mode for PWM TC, Use the Prescale counter
  //PWM1CTCR Should read all 0's
  PWM1CTCR &= 0xF0;

  //Create a 50Hz clock with 20ms period
  PWM1MR0=Period;
  //All these are bullshit initial values that should be changed at some point
  PWM1MR3=MS;
  PWM1MR4=1.5*MS;
  PWM1MR5=2*MS;
  PWM1MR6=1.5*MS;

  //Single edge output for PWM 3,4,5,6.  Enable said PWMs
  PWM1PCR = 0x00007800;
  //Enable the PWM Timer Counter and Enable PWMs
  PWM1TCR=0x09;
}

Of course, the next lines of code were added to the TaskConfig.h file.
Code: [Select]
#define TASK_PWM_INITIALIZATION 'z'                                     //Initialze PWM
extern void fnInitializePWMs(TTASKTABLE *);
//The next line was added into ctNodes[]
 ASK_PWM_INITIALIZATION,                                               //PWM initialization task
//The next line was added into the ctTaskTable[]
#ifdef TASK_PWM_INITIALIZATION
  { "z Initialize the PWMs",       fnInitializePWMs,NO_QUE,(DELAY_LIMIT)(2*SEC),0,UTASKER_STOP}, //test task
#endif

This task executes once, but I see no PWMs on the appropriate pins.  The PWM pin initialization code, however, does work perfectly if declared as an extern void InitializePWMs(void) function and having the main function call the initialization procedure before entering an infinite while loop all the while never entering utasker scheduling code.

I am left to conclude that something the utasker does wipes out my initialization procedure and continues to do so even if the initialization task is set to be periodic.  I was wondering if anyone could lend me a hand.

Thanks,
Kirk

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3234
    • View Profile
    • uTasker
Re: PWM Initialization
« Reply #1 on: April 09, 2009, 11:58:07 AM »
Hi Kirk

I don't see any problem with the initialisation method, although I haven't used the PWMs myself.

One possible explanation is that the PWM module is not powered. In the function _LowLevelInit(), the following line disables all peripherals by default

    PCONP = 0;                                                           // disable all peripheral power - the peripherals will be powered on later as used


and they then need to be enabled on a per-use basis. Is it possible that your initial tests outside the uTasker scheduler environment may have been starting with the initial state with all peripherals enabled (which is state the chip exits reset in)?

If this is the explanation, add a power up of the module at the beginning of your initialisation and this may be the solution:

    PCONP |= PCPWM1;                                             // power up PWM1


Regards

Mark