View previous topic :: View next topic |
Author |
Message |
johnl
Joined: 30 Sep 2003 Posts: 120
|
CCS Function Parameter "us()" |
Posted: Sun Mar 06, 2016 2:49 pm |
|
|
The example given for the setup_psmc() function uses "us(100)" and "us(25)" for the 4th and 8th parameters. I searched the CCS manual and well as the 16F1788 header file and didn't find any reference. I assume they stand for 100 and 25 microseconds. Could someone point to a definition?
Code: |
setup_psmc(1, PSMC_SINGLE,PSMC_EVENT_TIME | PSMC_SOURCE_FOSC, us(100),PSMC_EVENT_TIME, 0,PSMC_EVENT_TIME, us(25)); |
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun Mar 06, 2016 3:02 pm |
|
|
OK, I've got a headache just tryin to look at the datasheet but I'm thinking they might be the 'deadband control' timings ?
Section 25.4, page 256.......
I'm sure some prof could write a book and a 3 month course on just THIS peripheral of the PIC !!!
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Sun Mar 06, 2016 3:10 pm |
|
|
us, is a #define at the start of the code:
#define us(time) (int16)(time*(getenv("CLOCK")/1000000))
So it is just an int16 number of clock cycles needed for the particular number of microseconds. So with (say) a 20MHz clock, 10uSec, needs a value of 200 clock cycles.
The manual says the 4th and 8th parameters are 'period_time', and 'fall_time'.
Then if you look further down it says that these are in 'ticks' (of the master clock). Hence the define to work these out for you. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Mon Mar 07, 2016 7:47 am |
|
|
Ttelmah, did you reverse engineer that macro, or is it actually hiding in the documentation somewhere? I couldn't find it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Mar 07, 2016 7:55 am |
|
|
It's in the example code....
Just after the processor include, and clock setting. |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Mon Mar 07, 2016 11:04 am |
|
|
Here's the example from the manual which doesn't define the macro.
Where is the better example?
Code: |
Examples:
// Simple PWM, 10khz out on pin C0 assuming a 20mhz crystal
// Duty is initially set to 25%
setup_psmc(1, PSMC_SINGLE,
PSMC_EVENT_TIME | PSMC_SOURCE_FOSC, us(100),
PSMC_EVENT_TIME, 0,
PSMC_EVENT_TIME, us(25));
psmc_pins(1, PSMC_A);
Example Files: None |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Mar 07, 2016 12:26 pm |
|
|
It's in the examples directory....
Three examples to setup as a simple PWM, complementary PWM etc..
The bits in the manual are code 'snippets', not the actual examples. You can't compile the stuff in the manual, without all the other stuff (processor file, includes etc.). The actual examples show how to use the peripheral.
I'll repeat the old advice.
CCS required 'paperwork':
Manual
Chip data sheet.
Processor include file.
Examples/drivers.
Readme.
Last edited by Ttelmah on Mon Mar 07, 2016 12:45 pm; edited 1 time in total |
|
|
johnl
Joined: 30 Sep 2003 Posts: 120
|
|
Posted: Mon Mar 07, 2016 12:45 pm |
|
|
Silly me. I actually believed the statement "Example Files: None" in the manual!
Thanks to all who responded. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Mon Mar 07, 2016 12:47 pm |
|
|
I just updated my post while you were typing.
I don't know why the manual says 'none', but just about everything does feature in the examples, even if not specifically. |
|
|
|