how to obtain a 100 hz square signal using pwm timer in lpc1114/333

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

how to obtain a 100 hz square signal using pwm timer in lpc1114/333

941 Views
cancetin
Contributor II

Hello dear friends,

I need your please. I am new on  arm.  I am currently  work on a embedded project. In this project using LPC1114 microchip and drv8821 drive a stepper motor,  Thus I need the timer pwm square signal nearly 100 Hz. I have been reading user manual lpc1114  and i wrote a code but it failed. My code is below please analyze my code and help  me.  I am really stuck in  this  project.  My abmotor step is data sheet and my project schematic  pin 27 (pin 0_8)

#include "LPC11xx.h"

 
int main(void) {
 
    //Set up 16 bit timer for PWM operation
    LPC_IOCON->PIO0_8         = (LPC_IOCON->PIO0_8 & ~(0x3FF)) | 0x2;     //set up pin for PWM use (sec 7.4.23)
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7);                                  //enable clock signal to 16 bit timer0 (sec 3.5.14)
    LPC_TMR16B0->PR           = 0x0;                                      //set prescaler max value, not used here (sec 18.7.4)
    LPC_TMR16B0->MCR          = 0x10;                                     //set for reset on counter match (sec 18.7.6)
    LPC_TMR16B0->EMR          |= 0x20;                                    //set pin 27 to 1 on match (sec 18.7.10)
    LPC_TMR16B0->CCR          = 0;                                        //set to timer mode (sec 18.7.11)
    LPC_TMR16B0->PWMC         = 0x1;                                      //set channel zero to PWM mode (sec 18.7.12)
    LPC_TMR16B0->MR1          = ???????;                                     //set value for period (sec 18.7.7)
    LPC_TMR16B0->MR0          = ??????;                                      //set value for duty cycle (sec 18.7.7)
    LPC_TMR16B0->TCR          |= 0x3;                                     //enable and reset counter (sec 18.7.2)
    LPC_TMR16B0->TCR          &= ~(0x2);                                  //clear reset bit (sec 18.7.2)
 
    while(1){                                                     //infinite loop
    }
    return 0 ;
}
When I write this code , I see only dc 2,68V in pin 27  from oscilloscope screen. But i need a square signal 100Hz in this pin. Please help me. At the least i dont know what value assign instead of question marks(MR1 and MR0) in my code  for adjust the signal to 100Hz frequency.
Best regards,
 
Tags (4)
0 Kudos
1 Reply

703 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi CAN CETIN,

I would recommend you to use the LPCOpen software examples as reference, you could use the periph_blinky example as base for your application. You can download the software package from this link:

LPCOpen Software for LPC11XX|NXP 


Hope it helps!

Best Regards,
Carlos Mendoza
Technical Support Engineer

0 Kudos