This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

PWM generation help

Hi can anybody help me to clearly understand the generation of PWM in lpc2148 to control the servo motor ?

Thanks

  • Are you asking if anyone can prepare an 80 minutes long presentation of how PWM works, and how servo motors are controlled?

    Wouldn't it be much better if you spend some time asking specific questions?

  • HI i tried with the following pwm generation code but its doesn't generate the pulse required to drive servo

    int main(void)
    {
    while(1)
    
                    PINSEL0 |= 0x00028000;  //Enable pin 0.7   as PWM2
                    PWMPR  = 0x00000001;    //Load prescaler
                    PWMPCR = 0x00000404;    //PWM channel 2 double edge control, output enabled 404
                    PWMMCR = 0x00000003;    //On match with timer reset the counter
                    PWMMR0 = 0x000000FF;    //set cycle rate to sixteen ticks
                    PWMMR1 = 0x00000088;    //set rising edge of PWM2 to 2 ticks
                    PWMMR2 = 0x00000080;    //set falling edge of PWM2 to 8 ticks
                    PWMLER = 0x00000007;    //enable shadow latch for match 0 - 2
                    PWMTCR = 0x00000002;    //Reset counter and prescaler
                    PWMTCR = 0x00000009;    //enable counter and PWM, release counter from reset
                    PWMPCR = 0x00000000;
    
    }
    

  • I can see that you haven't bothered to debug your code. If you had, you would have noticed how many of your instructions that actually gets processed in that while loop.

    By the way - you sure that would be a good place for a while loop, even if you did have braces?

  • Yes i didn't debug the code. and i don't know to change the duty cycle of the pwm. i don't to set the exact value to PWMMR0,PWMMR1 and PWMMR2 match registers. help me how to do that.

  • Why? What have _you_ done, to help yourself?

    Don't you think programming is a task _you_ should do? Else, it's much better to buy the service from someone else.

    You just have to spend some own time on problems before you can expect people to help you when you are stuck. But you don't try. You go directly for "help" on a forum. "Programming-by-forum" isn't a good method to get somewhere. It is very slow. And making you very dependant.

    Start debugging - that's what the debugger was invented for. And do read the documentation for the processor - it was specifically written to tell how to what the processor can do. And how you do it.