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

Generating PWM with capcom

Hi everybody,

i'm working in an on board electronic company and i have a little problem.

I have to generate four different frequency outputs using Capcom2 unit on CC18 to CC21, my problem is that there is only two timers available for this capcom unit... And i really need 4 different outputs (frequency AND duty cycle) on these pins.

So i'm wondering if it's possible to use timers from capcom unit 1 and using outputs from capcom 2 unit or anything like that.

Thanks a lot to everyone who will help me.

P.S : i'm using an XC161CJ microcontroller

  • Well, after looking at my program, it seems that T0 and T1 are already used...

    So i'll may have to use other timers like T3/T4, and i don't know how to realize a duty cycle with them...

    Thanks again for any response.

  • Is there a reason why the double compare mode of the CAPCOM won't work?

  • Well, in fact i don't know if it is not working.

    For the two capture compare outputs wich are working i only use cc18 and cc19, i'm not using the second bank.
    And the two others must be on cc20 and cc21 because of the design of the electronic board.
    Maybe i'm doing a mistake, but according to what i read in the data-sheet, there's only two timers for the capcom unit 2, and, i need to create four independent frequency outputs.

    Maybe it's possible with only two timers, if it's the case, i would be pleased to know how !

    Thanks for the answer.

  • Double compare mode allows you to use one channel to cause a rising edge and the paired channel for the falling edge. You can have multiple events during one timer period. So you can configure the timer for the slowest (longest period) time (PWM controlled strictly by hardware) and then create other channels within that period but you need interrupts on each of the edges to calculate the next event for each additional PWM channel.

    Other possibilities could be to use the timer as free running and use compare mode 1 to toggle the events (again using interrupts, to control the period and duty cycle).

  • Thank you for the answer !

    Well, i think that your last solution is the best to fit my situation.
    But i already solved it using timers 3 and 4 and completing the output at each interruption.

    But i'll keep your answer in mind for my future developments.

    Thanks again.