Society of Robots - Robot Forum

Software => Software => Topic started by: Rebelgium on June 16, 2008, 05:46:55 PM

Title: PC PWM initialization and use on PIC18F4431
Post by: Rebelgium on June 16, 2008, 05:46:55 PM
I'm not the most experienced programmer, and I have some problems trying to program my PIC to use PWM to control some motors.
The PIC18F4431 is a powerull PIC specially designed for motor control, it has four PWM duty cycle registers and eight PWM pins.
The peripheral I'm using is the PCPWM (Power Control PWM).

But I just can't seem to find how to initialize this peripheral!
I would be very thankfull for a short summarization of what registers I have to program, and in what order. C code or assembly are also fine.

Also I'm not sure what to put in most of them.
This is my goal:
I want PWM0,2,5 and 6 to be independantly controllable PWM pins.
The period can be the same for all, but the duty cycle has to be modifyable in my code.

I more or less have these filled in:
PTCON0
PTCON1
PWMCON0
PWMCON1

but which ones do I also have to program? How do I program the period? the duty cycle?
And how does PWM "work" in code? Does it interrupt every period? Or what?

All I want is a peripheral outputting these four PWM signals, and I can change the duty cycle in my code.

Title: Re: PC PWM initialization and use on PIC18F4431
Post by: izua on June 20, 2008, 04:01:02 PM
I recall from the 16F family that the period is given by timer2, and the duty cycle is set up in individual registers. The device datasheet had some good examples for these PICs (check out CCPM modules)
Title: Re: PC PWM initialization and use on PIC18F4431
Post by: threewheeler7 on August 02, 2008, 10:19:59 AM
well it is nothing like setting up the 16f parts. i am working on a 4 brushed motor controller with one of these.