View previous topic :: View next topic |
Author |
Message |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
1us pulse reading with PIC18F |
Posted: Fri Apr 29, 2022 9:08 am |
|
|
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
|
|
Posted: Fri Apr 29, 2022 12:06 pm |
|
|
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
|
|
Posted: Sun May 08, 2022 8:01 am |
|
|
is there a clear explanation of this in the datasheet? _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Sun May 08, 2022 8:38 am |
|
|
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. |
|
|
|