LPC1769 PWM help

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC1769 PWM help

1,314 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bramvdpol on Tue Oct 09 03:33:53 MST 2012
Hi,

I'm using the LPC1769 to generate a PWM output with a varying dutycycle. I used the NXP PWM example as a base for this. I succeeded in doing this for channel 1. However, I need a second channel to be high when channel 1 is low, and to be low when channel 1 is high. I've tried several things, but was not able to get it to work. The best I got was to get the correct dutycycle for channel 2, but (slightly) delaying it wouldn't work.

Is there a simple way to invert a PWM output on a second PWM channel?

PWM.C:initialize variables
#include "lpc17xx.h"
#include "type.h"
#include "pwm.h"
#define ARRAYLENGTH 16
uint32_t dctest=0;//variable for choosing an integer from Array
const unsigned char dutyMod[ARRAYLENGTH] = {

   10,
   20,
   30,
   40,
   50,
   60,
   70,
   80,
   90,
   80,
   70,
   60,
   50,
   40,
   30,
   20,
      };


PWM.c: PWM_Set
void PWM_Set( uint32_t ChannelNum, uint32_t cycle, uint32_t offset )
{
  if ( ChannelNum == 1 )
  {
LPC_PWM1->MR0 = cycle;/* set PWM cycle */
LPC_PWM1->MR1 = cycle * 1/2;
LPC_PWM1->MR2 = cycle * 1/2;
LPC_PWM1->MR3 = cycle * dutyMod[dctest]/100;//channel one
LPC_PWM1->MR4 = cycle * 1/2;
LPC_PWM1->MR5 = cycle - (cycle * dutyMod[dctest]/100);//channel two
LPC_PWM1->MR6 = cycle * 1/2;

dctest++;//get next value from lookup table
if(dctest==(ARRAYLENGTH-1)){dctest=0;}//jump to first value if  final value found

/* The LER will be cleared when the Match 0 takes place, in order to
load and execute the new value of match registers, all the PWMLERs need to
reloaded. all PWM latch enabled */
LPC_PWM1->LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN | LER6_EN;
  }
  return;
}


PWMtest.c: Main
int main (void)
{    
  uint32_t cycle = PWM_CYCLE, offset = 0;

  /* SystemClockUpdate() updates the SystemFrequency variable */
  SystemClockUpdate();
 
  if ( PWM_Init( CHANNEL_NUM, 0 ) != TRUE )
  {
while( 1 );/* fatal error */
  }

  PWM_Set( CHANNEL_NUM, cycle, offset );
  PWM_Start( CHANNEL_NUM );

  while ( 1 )
    {
if ( match_counter1 != 0 )
{
  match_counter1 = 0;
  PWM_Set( CHANNEL_NUM, cycle, offset );
}
    }
}
0 项奖励
回复
1 回复

752 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 09 06:33:21 MST 2012

Quote:

Is there a simple way to invert a PWM output on a second PWM channel?

Yes, use interrupts :eek:

#1 Create s simple 1 channel PWM :)

#2 Enable it's interrupts ;)

#3 Switch a GPIO (or both) within PWM ISR :p

A sample of PWM interrupt usage is posted in:

#15 of http://knowledgebase.nxp.com/showthread.php?p=18409
0 项奖励
回复