#define CLOCK_SETUP 1 #define SCS_Val 0x00000020 #define CLKSRCSEL_Val 0x00000001 #define PLL0_SETUP 1 #define PLL0CFG_Val 0x0002003f #define PLL1_SETUP 1 #define PLL1CFG_Val 0x00000023 #define CCLKCFG_Val 0x00000007 #define USBCLKCFG_Val 0x00000000 #define PCLKSEL0_Val 0x00000000 #define PCLKSEL1_Val 0x00000000 #define PCONP_Val 0x042887DE #define CLKOUTCFG_Val 0x00000000 |
#include "LPC17xx.h" #include "debug_frmwrk.h" int c_entry(void) { LPC_SC->PCONP |= 1 << 6; // enable power for PWM1 LPC_SC->PCLKSEL0 |= 1 << 12; //PCLK = CCLK = 72MHz (?) LPC_PWM1->TCR = 0x00; LPC_PWM1->CTCR = 0x00; LPC_PWM1->MCR = 0x00; LPC_PWM1->CCR = 0x00; LPC_PWM1->PCR = 0x00; LPC_PWM1->LER = 0x00; LPC_PWM1->PR = 1 - 1; LPC_PINCON->PINSEL4 = (LPC_PINCON->PINSEL4 & ~(0x3 << 0)) | (0x1 << 0); //output to pin 2.0 LPC_PINCON->PINMODE4 = (LPC_PINCON->PINMODE4 & ~0x3) | 0x2; LPC_PWM1->MR0 = 1440000; /*set clock cycles for PWM. PWM freq = PCLK/MR0 (?)*/ LPC_PWM1->MR1 = 108000; // pulse width 1.5ms LPC_PWM1->LER = (1 << 0) | (1 << 1); //Apply changes LPC_PWM1->MCR |= 1 << 1; // interrupt on match0.Reset timer on Match0; LPC_PWM1->PCR = (1<<9); //--- PWM1 output LPC_PWM1->TCR = (1<<0)|(1<<3); while(1) { LPC_PWM1->MR1 = 1500; // pulse width 1.5ms LPC_PWM1->LER |= (1 << 1); //Apply changes } return (0); } int main (void) { return c_entry(); } #ifdef DEBUG /******************************************************************************* * @brief Reports the name of the source file and the source line number * where the CHECK_PARAM error has occurred. * @param[in] file Pointer to the source file name * @param[in] line assert_param error line source number * @return None *******************************************************************************/ void check_failed(uint8_t *file, uint32_t line) { /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* Infinite loop */ while(1); } #endif /* * @} */ |
//clkout (P1.27) to cpu clock LPC_PINCON->PINSEL3 &=~(3<<22); LPC_PINCON->PINSEL3 |= (1<<22); LPC_SC->CLKOUTCFG = (1<<8)|(9<<4)| 0; //enable and divide by 10 (max 16) |
//clkout (P1.27) to cpu clock LPC_PINCON->PINSEL3 &=~(3<<22); LPC_PINCON->PINSEL3 |= (1<<22); LPC_SC->CLKOUTCFG = (1<<8)|(9<<4)| 0; //enable and divide by 10 (max 16) |
while(1) { LPC_PWM1->MR1 = 1500; // pulse width 1.5ms LPC_PWM1->LER |= (1 << 1); //Apply changes } return (0); |
LPC_PWM1->PR = 1 - 1; |
LPC_PWM1->PR = 64 - 1; |
while(1) { LPC_PWM1->MR1 = 1500; // pulse width 1.5ms LPC_PWM1->LER |= (1 << 1); //Apply changes } return (0); |
LPC_PWM1->PR = 1 - 1; |
LPC_PWM1->PR = 64 - 1; |
LPC_SC->PCLKSEL0 |= 1 << 12; // PCLK = CCLK = 64MHz LPC_PWM1->MR0 = 1280000; // PCLK/1280000 = 50Hz LPC_PWM1->MR1 = 640000; // PCLK/(1+1ms) = 640000 |