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

CCS Function Parameter "us()"

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



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

CCS Function Parameter "us()"
PostPosted: Sun Mar 06, 2016 2:49 pm     Reply with quote

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: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Mar 06, 2016 3:02 pm     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Sun Mar 06, 2016 3:10 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 07, 2016 7:47 am     Reply with quote

Ttelmah, did you reverse engineer that macro, or is it actually hiding in the documentation somewhere? I couldn't find it. Question
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Mar 07, 2016 7:55 am     Reply with quote

It's in the example code....
Just after the processor include, and clock setting.
johnl



Joined: 30 Sep 2003
Posts: 120

View user's profile Send private message

PostPosted: Mon Mar 07, 2016 11:04 am     Reply with quote

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: 19552

View user's profile Send private message

PostPosted: Mon Mar 07, 2016 12:26 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 07, 2016 12:45 pm     Reply with quote

Silly me. I actually believed the statement "Example Files: None" in the manual!

Thanks to all who responded.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Mar 07, 2016 12:47 pm     Reply with quote

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