View previous topic :: View next topic |
Author |
Message |
poormeche
Joined: 13 Apr 2006 Posts: 3
|
very basic 18F4431 PWM help needed |
Posted: Thu Apr 13, 2006 7:40 am |
|
|
I appologize for the extremely basic questions, but I'm trying to use an 18F4431 to generate two distinct and controllable PWM signals to drive two non-identical DC motors. I had the capability to use the CCP modules on a 16F877A to monitor the encoder and drive the PWM signal for a single DC motor with PD control, but wanted to upgrade to the 18F because of its PWM capabilities (thus freeing up the other CCP module).
My problem seems to be that I can generate a waveform on a PWM output pin, but as this is my first real microprocessor experience of any kind, I can't figure out how to change the pulse width. At a fundamental level, I believe I just don't understand what the setup_power_pwm(), setup_power_pwm_pins(), and set_pwm_duty() function calls do and how they relate to each other. The CCS Compiler documentation is proving unenlightening for me.
Second appology for the long post To summarize, how do I configure two PWM pins on an 18F4431 such that I can vary the speed of my two motors? Additionally, some explanation of the behavior of the above mentioned functions would be helpful. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 13, 2006 11:25 am |
|
|
Quote: | I can't figure out how to change the pulse width. |
Look at the CCS example file: EX_POWER_PWM.C
In that program, they read the A/D value on pin A0 (which I assume is
connected to a trimpot) and use it to set the duty cycle of the Power
PWM module.
Look for the file in this folder: c:\Program Files\Picc\Examples
If you don't have it, email CCS support with your registration number
and ask them if they will send it to you. |
|
![](templates/subSilver/images/spacer.gif) |
poormeche
Joined: 13 Apr 2006 Posts: 3
|
|
Posted: Thu Apr 13, 2006 3:50 pm |
|
|
Thank you for the tip. That block of sample code is just the sort of thing I've been looking for. Hopefully the process will be demystified soon. ![Smile](images/smiles/icon_smile.gif) |
|
![](templates/subSilver/images/spacer.gif) |
poormeche
Joined: 13 Apr 2006 Posts: 3
|
|
Posted: Fri Apr 14, 2006 12:22 pm |
|
|
Thanks again for the help, I've gotten the PWM outputs working
However, this has led to a follow up question. Is it possible to use a CCP compare interrupt on a timer besides timer1? I would like to be able to hook my second motor encoder into timer2 (or timer5 or what have you) and use an interrupt to stop the motor after a prescribed number of encoder ticks (motor revolutions). However looking at the description of the CCP compare interrupt, it looks like it will only ever compare the value of the CCP to timer1.
I know I could probably swing the second motor's control with polling, but would prefer to use an interrupt if possible.
Thanks for any and all help! |
|
![](templates/subSilver/images/spacer.gif) |
|