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 using PCA

Hi,
I was trying to configure the CEX3 of Atmel TSC80251G2D( 80C251). Here follows my initialization code. I dont see a PWM output.
Any one has any comments? If so please help.

void pca_configure()
{
CMOD = 0x0; /* Internal Clock */
CCAPM3 = 0x42; /* PWM ON */
CCAP3H = 128; /* Duty cycle value for 50% */
CCAP3L = 128; /* Duty cycle value for 50% */
IPL0 = 0x40; /* Make PCA interrupt the highest priority */
IPH0 = 0x40; /* Make PCA interrupt the highest priority */

CR = 1; /* Start running */
EC = 1; /* PCA interrupt enable */
EA = 1; /* /* Global interrupt enable */
}


Thanks and Regards
Arun

Parents
  • Arun,

    What state do you see on the output pin? Is it constantly high or constantly low? Also, is there anything else in your code that works with the PCA? Keep in mind that the PWM function depends on the PCA counter being allowed to run freely. If you're manipulating CH or CL anywhere in your code, you could be constantly reloading a value that doesn't allow the PWM to change state. Try entering very low, or very high values for CCAP3H, CCAP3L. If you see glitches on the lines, then that might mean that the counter's getting hosed somehow.

Reply
  • Arun,

    What state do you see on the output pin? Is it constantly high or constantly low? Also, is there anything else in your code that works with the PCA? Keep in mind that the PWM function depends on the PCA counter being allowed to run freely. If you're manipulating CH or CL anywhere in your code, you could be constantly reloading a value that doesn't allow the PWM to change state. Try entering very low, or very high values for CCAP3H, CCAP3L. If you see glitches on the lines, then that might mean that the counter's getting hosed somehow.

Children
  • Hi ,
    Thanks a lot for the respose.What I see is a constant low. I have a pca_isr() which reloads the value for 50% duty cycle.
    void pca_isr(void) interrupt 6 using 2
    {
    CCF3 = 0;
    CCAP3H = 128; /*Value for 50% duty cycle*/
    CCAP3L = 128; /*Value for 50% duty cycle*/
    }
    I am expecting 50%duty cycle with this. But unfortunately I dont see any signal. Do you think any part of my configuration is wrong?

    Thanks and Regards
    Arun

  • Arun,

    While I've never tried this myself, I know that you're generally not supposed to modify the register CCAP3L manually when you're using the PWM mode. Basically, you load the value you want into CCAP3H and then when the CL portion of the PCA counter rolls over, the hardware loads the value from CCAP3H into CCAP3L for you. What it would do if you were constantly reloading it, I'm not sure.

    Did you try setting the PWM to other values? Try replacing the 128 reload with 5 or 250, for example and then see how the signal changes or if anything is different.

  • Hi Jay,
    Thanks for the help. It is working now. I stopped enabling the PCA interrupt and the reloading.

    Thanks again
    Arun