View previous topic :: View next topic |
Author |
Message |
salmankhalid16
Joined: 18 Dec 2009 Posts: 27
|
FAST I/O |
Posted: Thu Jun 26, 2014 10:06 am |
|
|
Hello All
i am facing a problem in executing a code
i am using PIC16F876 with 16MHz crystal
when ever i wrote the lines
output_high(PIN_C5)
output_low(PIN_C5)
now the pulse remains high for 1us. and then goes low
is their any other function so that the pulse remain high for just 250ns instead of 1us
as i am not using any delay in between both lines
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Thu Jun 26, 2014 10:54 am |
|
|
You have answered yourself, in your post name.....
#USE FAST_IO
However remember that _you_ then have to set the TRIS for the port yourself.
By default, the compiler uses 'standard_io'. In this mode, _it_ will set the tris for each bit as it is used.
So each output instruction gets replaced with 'set the tris for the bit'. 'Set the bit'. Because on your PIC, the TRIS register is in a different page to the I/O register, this involves a bank switch as well. Hence the time.
So if you specify #use FAST_IO for port C, the extra TRIS instructions are removed. However you are then going to have to set the TRIS for every other bit on PORTC, and do it correctly.
Best Wishes |
|
|
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Thu Jun 26, 2014 11:30 am |
|
|
Agreed with the FAST_IO. However I think the OP will end up with 500ns instead of 250. Had the same problem in a dsPIC33 running with a 25ns instruction time, took 50ns to switch the port with fast_io. Lived with it.
Regards |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Fri Jun 27, 2014 7:53 am |
|
|
He should get 250nSec.
For the single bit output, the compiler will use bit set/reset instructions, which are single instructions.
So it'll become a bit set, followed by a bit clear.
Since the actual pin update is at the same point in the instruction in each case, 250nSec at his 4MIPS. |
|
|
|