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

1us pulse reading with PIC18F

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



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

1us pulse reading with PIC18F
PostPosted: Fri Apr 29, 2022 9:08 am     Reply with quote

When using a PIC18F 16MHz clock, what is the time it takes to read the pulse from its input and control the output? Where is it written in this datasheet?
So, what should be the minimum pulse for the PIC18 ? For example, is it possible to read the incoming pulse at 1us and control the output? Or should it be a minimum of 100us? How do I calculate this and where is it in the Datasheet? What i want to do?
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 29, 2022 12:06 pm     Reply with quote

Download the PIC18 reference manual:
http://ww1.microchip.com/downloads/en/devicedoc/39500a.pdf
Go to page 244. Look at Figure 11-18: Successive I/O Operation.

Look at the 3rd line, titled: Instruction executed

Look at the 3rd column, titled: MOVF PORTB,W (This reads PortB)

You'll see that the Port pins are sampled after 1 Fosc clock.
Then 3 more Fosc clocks are necessary to complete the read cycle.

So with Fosc = 16 MHz, one Fosc = 62.5ns. So 4 x 62.5ns = 250ns.
Therefore it takes 250 ns to do a read instruction, to read from PortB
and put the data into the W register. This 250 ns period consisting
of 4 Fosc clocks is called one instruction cycle.
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

PostPosted: Sun May 08, 2022 8:01 am     Reply with quote

is there a clear explanation of this in the datasheet?
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun May 08, 2022 8:38 am     Reply with quote

as a quick reply...
yes.... need to read the 'instruction set' chapter.
1st, create a small compilable program that does ONLY what you want, something like read a pin on port b and send it to a pin on port c.
After it compiles, then printout the programname.lst file.
Now, locate the actual read pin on B, /write pin on port C (always use comments in your program...helps to see what's going on and where...
Lookup the machine code generated, in the 'instruction set', it says how many machine cycles it takes. Most only take one (except for jumps and branches.)
Write this down next to the lines of assembler code. Add then up.
One trick is that a PIC16 running @4MHz executes a 'machine cycle' in 1us, so if 'something' needs 12 machine cycles, it takes 12us to execute.
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