LED "capacitance" won't get lower


Results 1 to 17 of 17

Threaded View

  1. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by flotulopex View Post
    Hello,
    I've been reading some threads about the LED's capacity feature and that they can be used as "sensors".
    Now, I made a short program where I involve 3 LEDs to be discharged and measured in time like this:
    The shema is simple: one port connected to all Anodes (through a 330 ohms resistor) and three ports connected each to one Kathode. I use a 16F88 @ 20MHz.....etc....etc....etc....
    Check my webpage, www.srt.com/~jdgrotte, click on LED touch sensor.
    I did basically the same thing awhile back, used 8 LEDs, NO resistors, standard parallel LCD, and an 18F4620 @ 40Mhz.
    Most of the code is posted on the page itself. Should work with a 16F88 at 20Mhz, not sure, never tried.
    Check the video to see it in action (it's a crappy video, I've been meaning to update, never got around to it).
    This is actually my 18F4620 code:
    Code:
    looper var byte
    anode var porta.1              'common anode of all IR LEDs
    
    t1 var portc.5 : t2 var portc.4 : t3 var portc.1 : t4 var portc.0 : t5 var porte.2 : t6 var porte.1 : t7 var porta.4 'all IR LEDs cathodes pins
    
    touchval var word[7] : touchmin var word[7] : touchmax var word[7] : touchrange var word[7] : touchpos var word[7] : touchaverage var word[7]
    touchmidpoint var word[7] : maxval var byte : maxtemp var word
    
    skipsubs: 'generic setup I use for all my programs, YMMV
    flags=0 : pause 1000 : intcon=0 : intcon.7=1 : intcon.6=1 : intcon.5=1 : intcon2=0 : intcon2.2=1 : intco3=0 : pir1=0 : pir2=0 : pie1=0 : pie1.5=1 : pie1.4=1
    pie2=0 : t0con=0 : t0con.7=1 : t0con.6=1 : t0con=t0con+2 : t1con=0 : t2con=0 : t3con=0 : ccp1con=0 : ccp2con=0 : pwm1con=0 : eccp1as=0 : sspstat=0
    sspcon1=0 : sspcon2=0 : txsta=0 : txsta.6=0 : txsta.5=1 : txsta.4=0 : txsta.2=1 : rcsta=0 : rcsta.7=1 : rcsta.6=0 : rcsta.4=1 : baudcon=0 : baudcon.3=1
    spbrgh=4 : spbrg=16 : adcon0=0 : adcon1=$f : adcon2=$ff : cmcon=7 : cvrcon=0 : hlvdcon=0 : trisa=0 : porta=0 : trisb=0 : portb=0 : trisc=0 : portc=0 : trisd=0
    portd=0 : trise=0 : porte=0 : input switch1 : input switch2 : output led1 : led1=1 : led1=0 : pause 200 : led1=1 : pause 200 : led1=0 : pause 200 : led1=1
    pause 200 : led1=0 : pause 200 : led1=1 : pause 200 : led1=0 : pause 200 : led1=1 : pause 200 : led1=0 : pause 200 : lcdout $fe,1 : switchignorecount=0
    menu=1 : switchdelay=1000 : output serialdataoutputpin : input serialdatainputpin : touchmin = 65000 : touchmax = 100
    
    loop2:
    led1 = counter.0
    for looper = 1 to 7 'light an LED, even though you can't see it
        output anode : anode=1 : input t1 : t1=0 : input t2 : t2=0 : input t3 : t3=0 : input t4 : t4=0 : input t5 : t5=0 : input t6 : t6=0 : input t7 : t7=0
        select case looper
            case 1
                output t1 : t1 = 0
            case 2
                output t2 : t2 = 0
            case 3
                output t3 : t3 = 0
            case 4
                output t4 : t4 = 0
            case 5
                output t5 : t5 = 0
            case 6
                output t6 : t6 = 0
            case 7
                output t7 : t7 = 0
        end select
        pause 1 : anode = 0
        select case looper 'reverse bias that same LED
            case 1
                output t1 : t1 = 1
            case 2
                output t2 : t2 = 1
            case 3
                output t3 : t3 = 1
            case 4
                output t4 : t4 = 1
            case 5
                output t5 : t5 = 1
            case 6
                output t6 : t6 = 1
            case 7
                output t7 : t7 = 1
        end select
        pause 1
        select case looper 'switch that LED to an input to read it
            case 1
                input t1
            case 2
                input t2
            case 3
                input t3
            case 4
                input t4
            case 5
                input t5
            case 6
                input t6
            case 7
                input t7
        end select
    loop3a:
        'run a counter in a tight loop (loop3a) and keep checking and waiting for the particular LED input to drop from
        'a logic 1 to a logic 0 because the voltage sitting on the LED due to the internal capacitance drops 'slowly'
        touchval[ looper ] = touchval[ looper ] + 1 : if touchval[ looper ] > 65000 then goto kickoutloop3a
        'if we wait too long or the pin is stuck, we'll never get out of the loop
        select case looper
            case 1
                if t1 = 1 then goto loop3a
            case 2
                if t2 = 1 then goto loop3a
            case 3
                if t3 = 1 then goto loop3a
            case 4
                if t4 = 1 then goto loop3a
            case 5
                if t5 = 1 then goto loop3a
            case 6
                if t6 = 1 then goto loop3a
            case 7
                if t7 = 1 then goto loop3a
        end select
    kickoutloop3a:
        counter = counter + 1 'just a counter to show a 'heartbeat'
    next looper
    
    maxval = 0 : maxtemp = 0 'maxval keeps track of which led had the lowest value, maxtemp keeps track of the lowest value
    
    for looper = 1 to 7 'check al 7 LEDs to find the lowest one
        if touchval[ looper ] > maxtemp then
            maxtemp = touchval[ looper ] : maxval = looper
        endif
    next looper
    
    'clear out the line, then display the number of the darkest LED
    lcdout $fe , $80 , " " : lcdout $fe , $80 + ( 7 - maxval ) , DEC1 ( 7 - maxval ) : lcdout $fe , $c0 , " " : lcdout $fe , $c0 + ( 7 - maxval ) , $ff
    for looper = 1 to 7 : touchval[ looper ] = 0 : next looper
    goto loop2
    END
    Last edited by skimask; - 1st May 2007 at 21:25.

Similar Threads

  1. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  2. new and need help
    By smeghead in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 3rd November 2008, 20:19
  3. For next loop using: Led var Byte
    By quester in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th March 2008, 10:16
  4. LCD will not start
    By btaylor in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 24th May 2007, 02:30
  5. can't even flash an LED
    By bruno333 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th April 2005, 13:27

Members who have read this thread : 0

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