View previous topic :: View next topic |
Author |
Message |
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
Explanation of 30F5015 PWM functions |
Posted: Sun Mar 17, 2013 2:28 pm |
|
|
Hi! I have one 30F5015 controller and I was very surprised when I found it`s working with function which are not explained in the help file. So there is an example ex_motor_pwm.c, but the used functions are not fully explained. So can you give me a full list of the passed parameters and options of this functions.
For example in the example file:
Code: |
// Enable PWM module 1 in Free Running Mode with a
// prescaler of 4. For a period of approximately
// 13.1 ms with a 20 MHz input clock.
setup_motor_pwm(1,MPWM_FREE_RUN,4,0,0x7FFF);
|
I suppose the first "1" means first PWM module, MPWM_FREE_RUN is clear, 4 is the prescaler I suppose. What is "0"? Dead time? And how did they calculate 13.1 seconds? In my calculations this is not true..
Where can I find full info about this functions???
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Sun Mar 17, 2013 2:45 pm |
|
|
One obvious comment. They say 13.1mSec. The m means 'milli'.
Best wishes |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Sun Mar 17, 2013 3:05 pm |
|
|
I just took a quick glance at both the IDE help and the manual on their website. Both list that function with a full description of the parameters (except for the options which are in your PIC's .h file). The function setup_motor_pwm() is listed on page 257 of the manual and directly accessible in the help index by typing "setup_motor_pwm"
You didn't list your compiler revision, so I am guessing that might play into why you cannot find it (older revision maybe?), but definitely download a copy of the manual on their website. It's on the bottom of the software downloads page (make sure to get the PCD manual).
The options for the function vary by chip, so they will be located in your PIC's .h file. They should match up to the options in the chips control register, so a quick glance at the data sheet should indicate what they are specifically (found a handy equation on page 100 of the datasheet by the way).
Last edited by jeremiah on Sun Mar 17, 2013 3:12 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Mar 17, 2013 3:12 pm |
|
|
Quote: | Where can I find full info about this functions???
|
There are several places where you should look before asking on
the forum. These are:
- IDE help file
- PDF manual (PCD manual for 30F5015)
http://www.ccsinfo.com/downloads.php#manuals
- Readme.txt file in C:\Program Files\PICC\
- CCS forum archives (use search page)
http://www.ccsinfo.com/forum/search.php
- Google
http://www.google.com/
The level of irritation (and anger) is way up on the forum. It's obvious
part of it is caused by people not doing any work and wanting the forum
do it all for them. |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Wed Mar 20, 2013 6:16 am |
|
|
OK! I read everything which I found on motor pwm, but still there are some things I don`t understand. I have experience with power pwm modules. So here I have this :
Code: | setup_motor_pwm(number,MPWM_FREE_RUN,prescaler,postscaler,timebase); | number is the number of the pwm module
MPWM_ ... is the mode
prescaler and postscaler are OK.
The timebase as far as I understood should determine up to which number the module will count.
For example if I have 20Mhz quartz and prescaler of 4, this means 800ns per 1. In this case if I want to set the time base to 100us this means I have to use this
Code: | setup_motor_pwm(1,MPWM_FREE_RUN,4,0,125); |
Is this true?
Next I have to use only 1 of the 2 channels. In power pwm modules this is possible with override. How to achieve it here?
I tried with many combinations but I don't fully understand this.
I'm sure it has to be done in this section:
set_motor_unit(...);
Can you give me an example of overriding channel 1 of PWM module 1, so the active channel to be 2.
Third!
The duty cycle. In power pwm modules the duty cycle reaches 100% at 4xtimebase. Is this true here?
If I have timebase of 125 should I have to set 4x125 for 100% duty cycle?
Thanks! |
|
|
stoyanoff
Joined: 20 Jul 2011 Posts: 375
|
|
Posted: Thu Mar 28, 2013 3:31 pm |
|
|
The ex_motor_pwm.c example says:
Code: |
// Enable PWM module 1 in Free Running Mode with a
// prescalar of 4. For a period of approximately
// 13.1 ms with a 20 MHz input clock.
setup_motor_pwm(1,MPWM_FREE_RUN,4,0,0x7FFF);
|
Can anyone tell me how this 13.1ms is calculated?
Here are my calculations:
First I divide the frequency(20MHz) by 4(the prescaler) = 5MHz.
If we assume the module has 1 of every 4 input pulses as usually PIC microcontroller works I divide 5MHz by 4 one more time = 1.25MHz
This means 1/1.25MHz=0.8us period. In the function the period is set to 0x7FFF(32767), so if I multiply 0.8us by 32767 = 26.2ms!!!!
If we assume the module is incrementing by every input pulse (5MHz input frequency), this means 0.2us period and multiplied by 32767 = 6.6ms!!!
Where did this 13.1ms come from?
Thanks! |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1358
|
|
Posted: Thu Mar 28, 2013 5:41 pm |
|
|
jeremiah wrote: | (found a handy equation on page 100 of the datasheet by the way). |
Tcy = 2/Fosc
Other parameters come straight from the function parameters. |
|
|
|