Lpcxpresso 1769

13 replies [Last post]
cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

Hi,

I started to implement pwm on 1769.
I can debug code but ,its not working.I want to drive DC motor...ıs anybody implement this task before...
What are the single edge or anorher types defined in user manual...

0
Your rating: None

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ex-Zero
Offline
Joined: 2011-07-19
Posts: 2645

Quote:

...I can debug code but ,its not working...
That's a little bit general Smile

What code (PWM sample ?) and what isn't working?

Note: PWM Example in lpcxpresso_3.6.3_317\Examples\NXP\LPC1000\LPC17xx\NXP_LPCXpresso1769_MCB1700_2011-02-11.zip creates a wonderful 15 kHz signal

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

Zero you are the best of bests...

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

SystemClockUpdate(); gives me error...relevant to Version 2 :s
I am thorougly confused zero...

Ex-Zero
Offline
Joined: 2011-07-19
Posts: 2645

This sample is using another version of CMSIS. So if you copy just pwm.c and pwm.h in your own src folder, there can be a few errors.

SystemClockUpdate() is not needed in a standard LPCXpresso / CMSIS project Smile

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include 
#include 

#include "pwm.h"

#define CHANNEL_NUM            1

extern volatile uint32_t match_counter1;


// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

// TODO: insert other include files here

// TODO: insert other definitions and declarations here

int main(void)
{
// TODO: insert code here
  uint32_t cycle = PWM_CYCLE, offset = 0;
  if (PWM_Init( CHANNEL_NUM, 0 ) != 1)
  {
    while( 1 );            /* fatal error */
  }
  PWM_Set(CHANNEL_NUM, cycle, offset );
  PWM_Start( CHANNEL_NUM );
  while (1)
  {
  }
}

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

Standart code can be seen below.So when I remove SystemClockUpdate();
is it working correctly?

#include
#include

// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;

#include "lpc17xx.h"
#include "type.h"
#include "pwm.h"

#define CHANNEL_NUM 1

extern volatile uint32_t match_counter1;

/******************************************************************************
** Main Function 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 );
}
}
}

Ex-Zero
Offline
Joined: 2011-07-19
Posts: 2645

Original project is using CMSISv2_LPC17xx. Are you still using the original project?

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

Brother its ok,found it and try with version 2,zero thank you ....we wanna see you in Turkey...
You resolve my problem again smilar my I2C problem...I will never forget your help...
I am trying to write source in Turkish for make lpc pervasive in Türkiye.

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

Zero I need your help...I want to implement it on led...so
that cycle is defined 1200...
I can not calculate times...I wanna have 2 second cycle...
when cycle is 1200 my period will be o how many second ? ....
LPC_PWM1->MR0 = cycle;

Ex-Zero
Offline
Joined: 2011-07-19
Posts: 2645

If you run the original example:

1. clock = 72MHz

2. pwm clock = clock /4 = 18MHz

3. divider = 1200

4. result: 72E6/4/1200=15kHz

With 3.6E6 you will get 0.5 Hz Smile

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

That ı am succeed and its working with 0.5 hz,by the way when I check that PWM1 with led ,its not blinking :s so ı have again problem ...:S why its not working?

Ex-Zero
Offline
Joined: 2011-07-19
Posts: 2645

Quote:

...PWM1...
My board has no PWM1 pin Puzzled

cesimkaol
Offline
Joined: 2011-02-12
Posts: 77

I meant pwm channel one Smile

Ex-Zero
Offline
Joined: 2011-07-19
Posts: 2645

User manual UM10360 PWM Description:

Quote:

Two match registers can be used to provide a single edge controlled PWM output. One match register (PWMMR0) controls the PWM cycle rate, by resetting the count upon match. The other match register controls the PWM edge position. Additional single edge controlled PWM outputs require only one match register each, since the repetition rate is the same for all PWM outputs. Multiple single edge controlled PWM outputs will all have a rising edge at the beginning of each PWM cycle, when an PWMMR0 match occurs.

uint32_t PWM_Init( uint32_t ChannelNum, uint32_t cycle )
{
  if ( ChannelNum == 1 )
  {
 match_counter1 = 0;
 LPC_PINCON->PINSEL4 = 0x00001555; /* set GPIOs for all PWM pins on PWM */
 LPC_PWM1->TCR = TCR_RESET; /* Counter Reset */ 
 LPC_PWM1->PR = 0x00;  /* count frequency:Fpclk */
 LPC_PWM1->MCR = PWMMR0I; /* interrupt on PWMMR0, reset on PWMMR0, reset 
        TC if PWM matches */    
 LPC_PWM1->MR0 = cycle;  /* set PWM cycle */
 LPC_PWM1->MR1 = cycle * 5/6;
 LPC_PWM1->MR2 = cycle * 2/3;
 LPC_PWM1->MR3 = cycle * 1/2;
 LPC_PWM1->MR4 = cycle * 1/3;
 LPC_PWM1->MR5 = cycle * 1/6;
 LPC_PWM1->MR6 = 0; 
 /* all PWM latch enabled */
 LPC_PWM1->LER = LER0_EN | LER1_EN | LER2_EN | LER3_EN | LER4_EN | LER5_EN | LER6_EN;
  }
  else
  {
 return ( FALSE );  /* Unknown channel number */
  }
  NVIC_EnableIRQ(PWM1_IRQn);
  return (TRUE);
}

So what's not clear there?

feedback