|
|
View previous topic :: View next topic |
Author |
Message |
zmo Guest
|
setup_power_pwm |
Posted: Sat Aug 28, 2004 10:10 pm |
|
|
Hi,
I am using the 18F2431 to do motor control and would like to use the inbuilt PWM control function in CCS rather than hacking around directly in the registers. The readme and the .h file for the chip make reference to the function 'setup_power_pwm()' but I can't find any documentation for this function. Unlike the setup_timer_5() function, I can actually get the setup_power_pwm() function to compile if I give it seven arguments, but I don't know what those seven arguments are (presumably six configurations for the six PWM lines, and one configuration for general PWM control, but in what order?). I am about to start looking at the assembly to find out, but some actual offical documentation would be nice. Thanks for any assistance. |
|
|
controller Guest
|
|
Posted: Sun Sep 26, 2004 2:28 pm |
|
|
I am running into similar problems only I can't seem to get my code to compile if i try using any combinations of the SETUP_POWER_PWM functions. This is extremely frustrating.
How did you get it to compile zmo? |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sun Sep 26, 2004 6:37 pm |
|
|
Check the help file for the compiler. It is in there:
Quote: | SETUP_POWER_PWM( )
Syntax:
setup_power_pwm(modes, postscale, time_base, period, compare, compare_postscale, dead_time)
Parameters:
modes values may be up to one from each group of the following:
PWM_CLOCK_DIV_4, PWM_CLOCK_DIV_16,
PWM_CLOCK_DIV_64, PWM_CLOCK_DIV_128
PWM_OFF, PWM_FREE_RUN, PWM_SINGLE_SHOT,
PWM_UP_DOWN, PWM_UP_DOWN_INT
PWM_OVERRIDE_SYNC
PWM_UP_TRIGGER,
PWM_DOWN_TRIGGER
PWM_UPDATE_DISABLE, PWM_UPDATE_ENABLE
PWM_DEAD_CLOCK_DIV_2,
PWM_DEAD_CLOCK_DIV_4,
PWM_DEAD_CLOCK_DIV_8,
PWM_DEAD_CLOCK_DIV_16
postscale is an integer between 1 and 16. This value sets the PWM time base output postscale.
time_base is an integer between 0 and 65535. This is the initial value of the PWM base
timer.period is an integer between 0 and 4095. The PWM time base is incremented until it reaches this number.
compare is an integer between 0 and 255. This is the value that the PWM time base is compared to, to determine if a special event should be triggered.
compare_postscale is an integer between 1 and 16. This postscaler affects compare, the special events trigger.
dead_time is an integer between 0 and 15. This value specifies the length of an off period that should be inserted between the going off of a pin and the going on of it's complementary pin.
Returns:
undefined
Function:
Initializes and configures the Pulse Width Modulation (PWM) device.
Availability:
All devices equipped with PWM.
Requires
None
Examples:
setup_power_pwm(PWM_CLOCK_DIV_4 | PWM_FREE_RUN |
PWM_DEAD_CLOCK_DIV_4,1,10000,1000,0,1,0);
Example Files:
None
Also See:
set_power_pwm_override(), setup_power_pwm_pins(), set_power_pwmX_duty()
|
|
|
|
controller Guest
|
|
Posted: Thu Sep 30, 2004 4:18 pm |
|
|
Thank you so much.
I think my problem was thinking the .pdf manual was the only manual.
I didn't realize there was a help file that was being updated.
I use the MPLAB because CCS can't use the ICD-2 so i'm pretty much out of the loop as far as the CCS IDE.
Hopefully this will work now.
Thanks again! |
|
|
Guest
|
|
Posted: Fri Aug 26, 2005 3:16 pm |
|
|
I'm having some trouble relating the parameters of setup_power_pwm to PTPER and PTMRPS, and then figuring out resolution.
The 18F4431 errata sheet says the PWM period will be
[(PTPER+1)XPTMRPS]/(Fosc/4)
Is the "period" parameter sent to PTPER? It would seem so.
Postscale, I would assume, gets put into PTMRPS.
Resolution is log(Fosc/Fpwm)/log2.
Where does the prescalar enter into the above equations, and how would one set it from setup_power_pwm? If you use the prescalar, do you just replace Fosc with the scaled value?
How does resolution enter into set_power_pwmX_duty? 16383 is listed as the largest valid duty. Does this need to be adjusted as PWM resolution changes? Does the function handle scaling for you, or if you have 10 bits of resolution, does sending a number bigger than 10 bits wide into set_power_pwmX_duty. That is, if I have 10 bit resolution, does 0x1FF produce 100% duty? Do bigger numbers just cause wrapping??
Does the resolution equation change when pre or postscaling is used?
Thanks,
Scott |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Fri Aug 26, 2005 3:16 pm |
|
|
oops, that's my post. Thought I was logged in. Sorry |
|
|
sseidman
Joined: 14 Mar 2005 Posts: 159
|
|
Posted: Mon Aug 29, 2005 6:21 pm |
|
|
By way of helping myself, I did the test I should have done in the first place.
Using:
Code: | setup_power_pwm(PWM_FREE_RUN,1,1,800,0,0,0); |
I just started at 0, and used set_power_pwm0_duty to increment by 5, and spit out the value on a serial port.
The PWM duty cycle went to 100% at somewhere around 3200, and stayed there which means I have somewhere between 11 and 12 bits of precision.
Apparently, set_power_pwmx_duty does not scale. |
|
|
|
|
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
|