How to set port to high impedance? TRIS seems not to be working.


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2013
    Posts
    1,078

    Default How to set port to high impedance? TRIS seems not to be working.

    Hello. I've got some special LED displays.
    These are tiny 7 segment matrices, used in powerbanks and so on.
    The key difference is that leds there are plugged into forward-reverse matrix, so you need to multiplex them to get meaningful results.
    So in theory, operation is as follows:
    1. Set all ports to high impedance state.
    2. Pull high one port, pull down another port, so led connected thru it will be lit
    repeat above with different ports in loop, to get the things needed.

    The main issue is that either TRIS statements does not work, or HIGH-LOW statements interfere with them. In practice, this means that when I issue HIGH PORTB.3 or any other similar statement, some other PORTB pins also change their state. Adding TRIS.X=1 or 0 changes nothing. How to avoid this?
    led segments are connected to PIC pins via 220 ohm resistors.

    MCU is PIC16F886 and this is the sample code.

    Code:
    
    TRISA=%00000000  'S
    TRISC=%00000000   'set
    TRISB=%00000000   '
    ANSELH=%00000000   ' ADC OFF B
    ANSEL=%000000000 'configure PortA as digital except first 2
    ADCON1=%10000000  'adc justify
    OSCCON=%01110101  'SET FREQUENCY TO 8MHZ
    WPUB=%00000000    'turn off Pullups
    CM1CON0=0         'DISABLE COMPARATORS
    CM2CON0=0         'SAME HERE
    
    
    DEFINE OSC 8 'set oscillator speed  
    
    
    'adcin config
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50
    
    
    
    
    frak:
    high porta.6
    low portc.3
    pause 2
    low porta.6
    high portc.3
    pause 2
    '
    high portc.1
    low portc.2
    pause 2
    low portc.1
    high portc.2
    pause 2
    
    
    goto frak
    stop

  2. #2
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    Here is the pinout of the LED matrix.
    Name:  ledmatrix.jpg
Views: 227
Size:  314.4 KB

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    its called charlieplexing, forum examples abound
    Warning I'm not a teacher

  4. #4
    Join Date
    Aug 2011
    Posts
    408


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    Quote Originally Posted by CuriousOne View Post
    The main issue is that either TRIS statements does not work, or HIGH-LOW statements interfere with them. In practice, this means that when I issue HIGH PORTB.3 or any other similar statement, some other PORTB pins also change their state. Adding TRIS.X=1 or 0 changes nothing. How to avoid this?
    It sounds like you are describing the R-M-W (read-modify-write) effect that you get when setting one bit of a PORT output.
    When you do a bit operation on a PORT, the entire PORT is read, the bit is modified, and the entire PORT is written back.
    The easiest way to fix this is to use a part that has LAT registers, and always write to the LAT, read from the PORT.

  5. #5
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    In your example code you clear all TRIS bits making them all outputs. Try:
    Code:
    TRISA = 111111
    TRISB = 111111
    TRISC = 111111
    
    frak:
    TRISA.6 = 0
    TRISC.3 = 0
    HIGH PORTA.6
    LOW PORTC.3
    PAUSE 2
    LOW PORTA.6
    HIGH PORTC.3
    PAUSE 2
    TRISA.6 = 1
    TRISC.3 = 1
    
    TRISC.1 = 0
    TRISC.2 = 0
    HIGH PORTC.1
    LOW PORTC.2
    PAUSE 2
    LOW PORTC.1
    HIGH PORTC.2
    PAUSE 2
    TRISC = 0
    GOTO frak

  6. #6
    Join Date
    Feb 2013
    Posts
    1,078


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    As I understand, that RMW issue might happen due to current flowing in reverse direction thru the one of the led segments.
    For the latch part, I'll try one, too bad there is no search option to tell, which part has latch and which does not.

  7. #7
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    Newer PICs have LATx registers that eliminate the RMW issues.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: How to set port to high impedance? TRIS seems not to be working.

    charlieplexed correctly latx regs are not required at all
    Warning I'm not a teacher

Similar Threads

  1. 16F887 - PORT pins interfere with each other when set high/low
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 23
    Last Post: - 22nd June 2020, 16:06
  2. Replies: 28
    Last Post: - 9th March 2015, 15:35
  3. How to set a pin high an keep it there?
    By ShortBus in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 1st October 2009, 16:01
  4. 16F877A Correct set up for port a
    By enigma in forum General
    Replies: 4
    Last Post: - 30th March 2008, 12:00
  5. Pulling port high
    By the_antique in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 14th November 2005, 18:18

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts