16F877A won't keep relay on 100% of the time


Closed Thread
Results 1 to 21 of 21

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default boilerplate ??

    Hi coyotegd,
    by boilerplate I assume you refer to code that you reuse over and over like TRIS and Config fuse settings, that can be dicey in programming PICs as so many have their own quirks. You might think good thoughts about posting that boiler plate code so as we can smoke it over. You know, I think I would try your code on a port B pin, as Port A has lots of confusing analog stuff to contend with, the process of elimination.
    JS
    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.

  2. #2
    Join Date
    Oct 2005
    Location
    Las Vegas, Nevada, USA
    Posts
    27


    Did you find this post helpful? Yes | No

    Default The entire program

    Here is the entire program I am working with just to get the relay to operate properly:

    @ DEVICE HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF

    Define OSC 20

    ADCON1 = 7 ' Digital I/O for Registers A & E
    TRISA = 0 ' PORTA as outputs
    PORTA = 0 ' PORTA pins low
    TRISB = 255 ' PORTB as inputs from Mach3
    PORTB = 255 ' PORTB pins high for active low
    OPTION_REG.7 = 0 ' Enable PORTB pull-up resistors
    TRISC = 0 ' PORTC as outputs
    PORTC = 0 ' PORTC pins low for active high
    TRISD = 0 ' PORTD as outputs
    PORTD = 0 ' PORTD pins low for active high
    TRISE = 7 ' PORTE as inputs from machine for x, y, z travel limits
    PORTE = 7 ' PORTE pins high for active low

    ChrgPmp var PORTB.0 ' Input for Mach3 charge pump
    CntCP var byte ' Count check for 12kHz on PORTB.0
    Estop var PORTA.0 ' Send Emergency stop to Mach3
    LPTports var PORTA.1 ' Enable parallel ports
    Aux var PORTA.2 ' Auxilary power
    Coolant var PORTA.3 ' Coolant power
    Spindle var PORTA.4 ' Spindle power
    SpinDir var PORTA.5 ' Spindle direction
    XLED VAR PORTD.0
    YLED VAR PORTD.1
    ZLED VAR PORTD.2
    X var byte ' Counter for pin cycling

    '----------

    MAIN:
    count chrgpmp, 1, cntcp ' Count freq. on B0, Mach3's 12kHz
    if (cntcp >= 11) and (cntcp <= 13) then ' Freq. must be between 11 & 13kHz
    lptports = 1
    else
    LPTports = 0
    goto main
    endif
    'gosub CK_PORTB
    'gosub CK_PORTE
    goto main
    end

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


    Did you find this post helpful? Yes | No

    Default

    Are you on the correct pin. At the beginning you said you were using PORTA.2.
    Code shows PORTA.1?

    What about CMCON = 7
    Dave
    Always wear safety glasses while programming.

  4. #4
    Join Date
    Oct 2005
    Location
    Las Vegas, Nevada, USA
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Your right

    You are right, but A2 is correct. When I first posted, I change my code for clarity. I probably should have used the exact same code all the way through. When I said A1 earlier, it should have been A2. Good find. Thanks for looking.

    I think everyone should STOP TRYING TO FIGURE THIS OUT. I tested the programmed PIC with a breadboarded darlington and relay and it works like a champ. No split-second low on A2 approximately every second during a proper A2 high when B0 frequency is between 11 and 13kHz.

    I must have a conflict in my power supply or other PIC peripheral connections. I'm sure I'll find the answer when I look very closely at my schematic.

    Thanks everyone.

  5. #5
    Join Date
    Oct 2005
    Location
    Las Vegas, Nevada, USA
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Sorry, but I did get some CCP and interrupt study

    When I use a 12kHz TTL signal from my Function Generator, the relay works fine. However, when I use the 12kHz signal from Mach3, I get the spastic relay. I scoped the Mach3 signal after passing through the transceiver, it appeared to be a good 12kHz 5V to 0V signal.

    I am going to run the Function Generator signal through the parallel port as if it's Mach3's, and thereby through the tri-state transceiver. I'm narrowing it down and will find it.

    Thanks for letting me vent.

  6. #6
    Join Date
    Oct 2005
    Location
    Las Vegas, Nevada, USA
    Posts
    27


    Did you find this post helpful? Yes | No

    Default Can someone explain this to me

    Function Generator 12.1kHz TTL 3V signal directly on B0 and the relay works great. Ditto when the Generator's signal is run through PC parallel port input and tri-state transceiver to boost to 5V square wave.

    Mach3 PC software transmitting 3V TTL through parallel printer port. Signal placed directly on B0, spastic relay. Ditto when the signal is passed through the tri-state transceiver.

    Both signals look exactly the same on an oscilloscope. Both signals find the same ground as the PIC, relay, transceiver, parrallel port and power supply.

    I even took the signal directly from the parallel port attached to the PC in case the cable was defective.

    Arghhhhh.....

    BTW, I believe "CMCON = 7" would be a moot entry. "ADCON1 = 7" makes ports A and E digital I/O rather than analog.
    Last edited by coyotegd; - 7th September 2007 at 22:03.

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


    Did you find this post helpful? Yes | No

    Default

    BTW, I believe "CMCON = 7" would be a moot entry. "ADCON1 = 7" makes ports A and E digital I/O rather than analog.
    You may want to read this. It explains ADCON and CMCON.
    http://www.picbasic.co.uk/forum/showthread.php?t=561
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. First time with external oscillator - 16F877a Not working
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 15th October 2009, 17:14
  2. I don't understand this code!
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 46
    Last Post: - 13th February 2008, 02:55
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. Serout2/serin2 Pbp Problem
    By SOMRU in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 11th December 2006, 19:55
  5. Timer in real time
    By martarse in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th July 2005, 14:24

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