View previous topic :: View next topic |
Author |
Message |
valemike Guest
|
Glitchless re-write of TRISD/PORTD/LATD ? |
Posted: Tue Jul 05, 2005 9:38 am |
|
|
I want to change TRISD from/to:
'0000 0011' -- initial trisd // 0x03
'1010 0011' -- desired new trisd // 0xA3
I want to preserve the lower nibble RD3:RD0 and leave its current pin states alone, while rewriting RD7:RD4.
1st method: using PORTD directly.
Code: |
temp_portd = PORT_D;
[manipulate temp_portd with some logical | and & masks]
PORT_D = temp_portd;
set_tris_d(0xA3);
|
2nd method: using LATD:
Code: |
temp_latd = LATD;
[manipulate temp_latd with some logical | and & masks]
LATD = temp_latd;
set_tris_d(0xA3);
|
What is the proper way to change it and get glitch-free operation? I've been using method #2 for several months, but i'm now suspicious since i think i'm getting glitches. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Tue Jul 05, 2005 10:26 am |
|
|
I've played with the TRIS registers directly, in the same manner that you are suggesting, with no glitches.
I recently taught a PIC course where we read a DS18S20 one wire temperature sensor. This was connected to port C. If you're not familiar with the 1 wire protocol, it's pretty fussy. Lots of changes in pin direction, and the timing is very critical for success.
Anyway, once we could read the temperature of the sensor, we expanded on what we did, and got the PIC to send the temperature to a host PC using the USART on pins C6 and C7. No glitches at all.
What I did was:
Code: | #byte TRISC = 0xf94
// if I need to change C2 from an output to an input, I'd:
TRISC = TRISC | 0x04;
// if I need to change C2 into an output, I'd:
TRISC = TRISC & 0xfb; |
This was all happening concurrently with the USART spitting out and receiving data. No glitches. Hope this helps. |
|
|
valemike Guest
|
|
Posted: Tue Jul 05, 2005 11:01 am |
|
|
Thanks. Actually what i was asking was not whether i can play with TRISD directly, but rather, how would I pre-load the pins so that when i flipped the TRISD bits to outputs, the pins would immediately assume the logical outputs states that i want.
I'm thinking more and more now that my glitches are coming from the ECCP though. I seem to be getting a brief unwanted pulse. oh well. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1908
|
|
Posted: Tue Jul 05, 2005 11:21 pm |
|
|
Oh! Just write whatever you want to the latch. When you flip the TRIS to be output, the pins will be whatever you wrote into the latch.
Sorry! I didn't realize what you were asking the first time. |
|
|
|