CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

very basic 18F4431 PWM help needed

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
poormeche



Joined: 13 Apr 2006
Posts: 3

View user's profile Send private message

very basic 18F4431 PWM help needed
PostPosted: Thu Apr 13, 2006 7:40 am     Reply with quote

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 Embarassed 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.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 11:25 am     Reply with quote

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.
poormeche



Joined: 13 Apr 2006
Posts: 3

View user's profile Send private message

PostPosted: Thu Apr 13, 2006 3:50 pm     Reply with quote

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
poormeche



Joined: 13 Apr 2006
Posts: 3

View user's profile Send private message

PostPosted: Fri Apr 14, 2006 12:22 pm     Reply with quote

Thanks again for the help, I've gotten the PWM outputs working Smile

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group