Swaping I/O back and forth during runtime 12F683


Closed Thread
Results 1 to 6 of 6
  1. #1

    Default Swaping I/O back and forth during runtime 12F683

    I have a 12F683 with an analog input device on GP0. No problem with that.
    I want to piggy back an lcd on the same pin and drive it between adc aquisition.

    So in escence during runtime i want to swap the pin back and forth between an adc input and a serial output.

    My analog device is quite high impedance so the high low pic output will not affect it. Also the lcd input is high impedance and should not affect the voltage data, and should ignore is as invalid serial data.

    I want to

    1) initialise pin as analog input and take a reading
    2) initialise pin as serial output and send data to lcd
    3) Repeat

    Any issues? I'm only taking adc readings 5 times a second or so. Rest of the time pin can be sending serial data to lcd.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I gave it a try, could not get it to work correctly

    Two 10k resistors as a voltage divider giving a reading of 127 with the serial output on a different pin.

    When the serial output is placed on the ADC pin the ADC value drops to 16. The ADC value will change if the divider is changed and the serial still works, just getting incorrect values.

    Test code:
    Code:
       ' ADC TEST  FOR CHANNEL 2  WITH SERIAL2 OUT
        '<FL_PIC12F675>'
        '<FL_PBPW>'
        DEFINE OSC 4
        @ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _CP_OFF
        CMCON=7
    '    ANSEL=%00000100
    '    TRISIO = %000100
        RESULT   VAR BYTE   'A/D CONVERSION RESULT STORAGE BYTE
    
        START:  'A HEART BEAT
        GPIO = %010000:PAUSE 500:GPIO = %000000:PAUSE 500
        SEROUT2 GPIO.2, 16780, ["RESULT ",DEC RESULT,$a,$d]
        PAUSE 250
        GOSUB ADC_2      'STARTS THE READING OF ADC CHANNEL 2
        GOTO START
    
        ADC_2:  'READ AN2  GPIO2
        PAUSE 100
        ANSEL=%00000100
        TRISIO = %000100
        GPIO = %000100
        ADCON0 = %00001001      'TURNS ADC ON
        GOSUB   READ_AD
        RESULT = ADRESH    'PLACES THE ADC VALUE INTO VAR
        ANSEL=%00000000
        TRISIO = %000000
        RETURN
    
        READ_AD:   'DOES THE ADC CONVERSION
        PAUSE   50
        ADCON0.1=1
        WHILE ADCON0.1=1:WEND
        RETURN
    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    I'll give it a try in due course. The impedance of my adc source is 10k so is unaffected by the input/output change. Thanks

  4. #4


    Did you find this post helpful? Yes | No

    Default almost working

    I've been trying this today and it almost works.

    The adc in works as does the serial out and i can see the data on my scope, but the serial lcd does not recognise it. I'll get my logic probe on it and see what values it thinks are arriving.

    I believe the problem is that the lcd is expecting N9600 (idle high)

    however when you switch from the adc to serial output the pin goes low and it won't come back up even if I send a high pin command? As soon as the serial data has been sent it then idles high. So the false low at the start is corrupting the data i believe.

    I'll keep trying. Any thoughts. I tried serout and debug out same result.

  5. #5
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    you want to modify Start /goto Start section so it doesn't touch GPIO.2 bit.
    Code:
        START:  'A HEART BEAT
             GPIO = %010100:PAUSE 500:GPIO = %000100:PAUSE 500
             SEROUT2 .....
             .....
             GOTO START
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  6. #6


    Did you find this post helpful? Yes | No

    Default

    I have this working now. You are limited a bit by the adc input, but so long as any switch you implement is held above logic high say >4v and has enough impedance not to effect the serial data when it appears on the pin, then you can have an input on the adc so long as you stay within that top 1 volt. A few switches and carefully choosen pd resistors works.

    Nice for 8 pin pics as I was short of an output pin for my lcd. Now I have serial output and adc input on the same pin

Members who have read this thread : 1

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