PIC16F628a Schmitt Trigger Input


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    22

    Default PIC16F628a Schmitt Trigger Input

    How would I program and wire a circuit to use a toggle switch on RA5? I've been unable to get it to work.

    ~ Dave

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by yankee View Post
    How would I program and wire a circuit to use a toggle switch on RA5? I've been unable to get it to work.

    ~ Dave
    Hi Dave, . . . use a toggle switch . . . do you mean as an input or toggle as an output ? This chip will not output on RA5, so I will assume as an input. A simple if then loop to check port status will do fine. Schmitt trigger has higher and lower readings than TTL to switch say 1volt and 4 volt as opposed to about 1/2 supply voltage.
    Code:
    IF PortA.5 THEN
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    I haven't tried this yet. Does this look like it will work?

    Code:
    @ device  pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
    
    
    TRISA = %00000100							' Make all port a pins inputs except for 5
    TRISB = %00000000							' Make port b pins outputs
    
    B15 VAR PORTB.7
    
    switch:
    
    if porta.5 = 0 then cal
    if porta.5 = 1 then main
    
    goto switch
    
    cal:
    
    low B15
    pause 3000  ' pause 3 seconds
    HIGH B15
    pause 3000
    if porta.5 = 0 then cal
    
    goto switch
    
    main:
    
    IC performs main routine

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by yankee View Post
    I haven't tried this yet. Does this look like it will work?

    Code:
    @ device  pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
    
    
    TRISA = %00000100							' Make all port a pins inputs except for 5
    TRISB = %00000000							' Make port b pins outputs
    
    B15 VAR PORTB.7
    
    switch:
    
    if porta.5 = 0 then cal
    if porta.5 = 1 then main
    
    goto switch
    
    cal:
    
    low B15
    pause 3000  ' pause 3 seconds
    HIGH B15
    pause 3000
    if porta.5 = 0 then cal
    
    goto switch
    
    main:
    
    IC performs main routine
    I would probably do as follows:
    Code:
    @ device  pic16F628A, INTRC_OSC_NOCLKOUT, wdt_off, mclr_off, lvp_off, protect_off
    PortA = %00000000    ' set ports to known state
    PortB = %00000000    ' outputs will initialize in low state
    
    TRISA = %00100000 ' Make all port a pins outputs except for 5
    TRISB = %00000000 ' Change PortB from HI Q to Outputs that will initialize low
    	
    i VAR BYTE ' counter variable
    cmcon = 7  ' disable comparators
    Switch:
        IF PortA.5 = 1 THEN Main
        PortB.7 = 0
        FOR i = 1 TO 30
        pause 100  ' pause 100 ms 30 times
        NEXT i
        PortB.7 = 1
        FOR i = 1 TO 30
        pause 100
        NEXT i
    GOTO Switch
    
    main:
                  ' do your main stuff here
    
    goto switch   ' go back to switch and check
    
    
    end
    I would change the pauses in case you need to interrupt the code,
    and remove redundant loops
    Last edited by Archangel; - 12th March 2009 at 17:05.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Jan 2009
    Posts
    22


    Did you find this post helpful? Yes | No

    Default

    Thanks Joe! That worked really slick. Now, I just have to figure out why your code works so well. I could definitely use a code for Dummies book. I'm not understanding the "FOR i = 1 TO 30."

    ~ Dave

Similar Threads

  1. Need Help... 16f630 Schmitt Trigger
    By tohu thomson in forum mel PIC BASIC
    Replies: 1
    Last Post: - 13th August 2007, 15:13
  2. build in schmitt trigger
    By mischl in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 5th April 2007, 16:16
  3. Timing input pulses and re-outputting them
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 28th February 2007, 01:50
  4. Schmitt trigger on IRED xmtr
    By Michael in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st February 2006, 13:01
  5. PIC16F628A input question
    By yankee in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th January 2006, 03:35

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