I’m a beginner in LPC1768 & freertos development, so I hope I could get some help for my project
I’m using freeRTOS LPC1768 rowley crossworks demo as base config for my project. I’ve modified the code by removing all demo tasks except for the flash.c and uIP task, and added my own PWM code to the project
the issue was that both of the flash.c and uIP task work perfectly, however my PWM are not working. I’ve configured for the PWM to be channeled to on-board LED. From debugging, it seems that the PWM is initialized, but never run. Below is the PWM code:
LPC_SC->PCONP |= 1 << 6; // enable power for PWM1
LPC_SC->PCLKSEL0 |= 1 << 12; //PCLK = CCLK = 64MHz
LPC_PWM1->PR = 64 - 1; //prescale to obtain 1MHz
LPC_PINCON->PINSEL4 = (LPC_PINCON->PINSEL4 & ~(0x3 << 0)) | (0x1 << 0); //output to pin 2.0 (LED 11). From this, the LED is turned off,showing initilization are taking place
LPC_PINCON->PINMODE4 = (LPC_PINCON->PINMODE4 & ~0x3) | 0x2; //no pull-up/down
LPC_PWM1->MR0 = 20000; /*set clock cycles for PWM. PWM freq = PCLK/MR0 (?)*/
LPC_PWM1->MR1 = 1500; // pulse width 1.5ms
LPC_PWM1->LER = (1 << 0) | (1 << 1); //Apply changes to MR
LPC_PWM1->MCR |= 1 << 1; // interrupt on match0.Reset timer on Match0;
LPC_PWM1->PCR = (1<<9); //set output to PWM1
LPC_PWM1->TCR = (1<<0)|(1<<3); //reset & enable counter
}
when I’m not using freeRTOS, the PWM would already run after the LPC_PWM1->TCR = (1<<0)|(1<<3); line…
however, with freeRTOS, the PWM doesnt run after LPC_PWM1->TCR = (1<<0)|(1<<3); line…
any idea on whats happening?
really appreciate any help.thank you in advance
We can’t normally comment on chip specific peripheral configurations, there are too many chips with too many peripherals and it is outside the scope of FreeRTOS support, but if you say the PWM works without FreeRTOS then I think it is ok to assume the peripheral configuration is ok.
I notice in your code that you are using an interrupt. What frequency are interrupts generated? What is the interrupt handler doing? What is the priority of the interrupt handler? If the handler has a priority above configMAX_SYSCALL_INTERRUPT_PRIORITY then the kernel should not effect its timing, but that can only be done if the handler is not calling FreeRTOS API functions.
From your questions, I’ve realize I had to include NVIC interrupt handler inside my program whilist I didn’t have to when trying my program without freeRTOS
-I’m trying to produce PWM with 50Hz frequency.
-The interrupt handler I’ve included is to check & clear the interrupt flag
-I set 6 for the pwm interrupt handler priority, (configPWM_INTERRUPT_PRIORITY) in FreeRTOSconfig.h
still the code doesnt work. Any clue for me? Sorry, I’m really a beginner in freertos & still struggling after reading online manuals, really appreciate some help here
and my program worked in this freertos template using KEIL.
But when I tried my PWM code to examples from freertos (LPC1768 for crossworks & IAR), the PWM does not work anymore
this starts to confuse me. I tried debug my code. The pwm task is running, the interrupt are called, but the LED (as pwm output) does not light up…it seems that the LED stayed at the initialization state only…
If I understand you correctly you have the pwm and led working in a keil project, but when you move the exact same setup and interrupt code to the Rowley (or IAR?) project the pwm works but the led does not?
There must be a difference in the hardware setup up. Could it be that
the Keil project is doing some extra configuration that you have not seen because it does it before main() is called?
or
that the pwm and interrupt code is the same in both, but only the keil project is configuring the pin used by the led to be driven by the pwm?
or
the library code used to setup the pin used by the led has a bug in the Rowley (or IAR) version that is not in the keil version.
The io port will have some registers that set up things like if it is input or output, if the port is powered up at all, which of the multiplexed functions the pin is using (some pins can be used in different modes and as io for different peripherals. Can you view these registers in the debugger in both the Keil and Rowley (or IAR) projects to ensure they match?
Unfortunately those lines don’t show anything other than one compiler is loading a constant using program counter relative addressing and the other isn’t. I think the intention is to see what values end up in the registers after all the initialisation is complete, rather than look at how the values are written to the registers.