View previous topic :: View next topic |
Author |
Message |
jojos
Joined: 30 Apr 2007 Posts: 64
|
Real time Port conflict |
Posted: Mon Mar 17, 2008 8:17 am |
|
|
Hi. I use PIC 18F2520.Compiler version 3.249
I use a real time clock (RTC)from maxim DS1307. The pin for the data of the clock is PORTC.2 and for the clock pulses is PORTC.1 .
For my project also I use the pin PORTC.3 to send a high-low pulse when a particular event occurs. During the development of the project I noticed that the time or the date or even both of them wasn’t displayed correctly e.g. on the seconds appeared ‘??’or > symbols e.t.c. After a small searching I came up to a conclusion that the pulse on PORTC.1 . was affecting RTC. Also as the frequency of the pulse increased the symbols appeared faster on the display screen . e.g. if the pulse had a frequency of 2KHz then the odd symbols appeared almost instantly .If the pulse had a frequency of 500 Hz then the odd symbols appeared in x seconds ,where x is not a specific time.I changed the port of the pulse to the PORTB.5 Then I saw I didn’t had any problem with the RTC. Is it possible that when the pulse is on the same PORT ,as the data and clock signals of the RTC , can affect it and if yes is there any solution apart from changing the port of the pulse? Thank you |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: Real time Port conflict |
Posted: Mon Mar 17, 2008 10:03 am |
|
|
It might be that you are accessing PORTC.3 using code that does not preserve the state of PORTC.1 and PORTC.2. Are you using bit_set(), or are you setting the entire PORTC?
Normally you should be able to use these pins independently without interaction. There is the issue of Read-Modify-Write possibly corrupting the output, but if you use the latch outputs, that should not be a problem.
Robert Scott
Real-Time Specialties |
|
|
Matro Guest
|
|
Posted: Mon Mar 17, 2008 10:07 am |
|
|
Could it be a crosstalk problem at the PCB level?
Matro. |
|
|
jojos
Joined: 30 Apr 2007 Posts: 64
|
|
Posted: Tue Mar 18, 2008 1:08 am |
|
|
I configured the pin for the pulse as
#bit Pulse_Output = PORTC.3
and to turn it on i use Pulse_Output=ON;
and to turn it low
Pulse_Output =OFF;
I don't use bit_Set instruction |
|
|
jojos
Joined: 30 Apr 2007 Posts: 64
|
|
Posted: Tue Mar 18, 2008 3:57 am |
|
|
I used the latch output LATC.3 instead of the PORTC.3 ,for the pulse ,and it worked. My concern is this know: Is latch output more vulnerable to noise than PORT outpout or not ? |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
|
Posted: Tue Mar 18, 2008 9:49 am |
|
|
jojos wrote: | I used the latch output LATC.3 instead of the PORTC.3 ,for the pulse ,and it worked. My concern is this know: Is latch output more vulnerable to noise than PORT outpout or not ? |
OK, you found the solution. The difference is when you say
then the PIC reads all 8 bits from the pins of Port C, sets bit 3, then writes the resulting 8 bits back out to Port C. If there is any noise or load on PORTC.1 or PORTC.2 so that the pin does not read back the same as it was last written, then the read-back will become permanent in the latch.
But when you say
then the PIC reads all 8 bits of the internal latch, sets bit 3, then writes the result out to the latch. The internal latch is shielded from whatever is going on out there on the pins, so it is more reliable.
Robert Scott
Real-Time Specialties |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Mar 18, 2008 10:00 am |
|
|
If you use the CCS pin i/o functions, the compiler automatically does
this for you. It sets the correct TRIS and it uses the Latch register.
Here's the code from the .LST file for the test program shown below:
Code: |
... output_high(PIN_C3);
0018: BCF TRISC.3
001A: BSF LATC.3
|
Code: | #include <18F2520.H>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000)
//================================
void main()
{
output_high(PIN_C3);
while(1);
} |
|
|
|
|