Harware of Software for 16F688?


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default Harware of Software for 16F688?

    Hi,

    I built a prototype alarm system which is based around the 16F688. I also have the outputs going to a ULN2003A to turn on and off some relays. For the power supply, I have a standard 5V regulator with input and output .1uF
    caps on each side. The beginning of my code looks like this:

    @ DEVICE PIC16F688, INTRC_OSC_NOCLKOUT, WDT_OFF, PWRT_OFF, MCLR_OFF,
    BOD_OFF,PROTECT_OFF

    DEFINE OSC 4
    TRISA = %00111011
    TRISC = %00101110
    ANSEL = %00000000
    CMCON0=7
    BRAKESO VAR PORTC.0 'BRAKES OUTPUT
    LIGHTS VAR PORTA.2 'PARKING LIGHT OUTPUT
    BUTTON1 VAR PORTC.1 'TRANSMITTER NUMBER ONE BUTTON
    BUTTON2 VAR PORTC.2 'TRANSMITTER NUMBER TWO BUTTON
    BUTTON3 VAR PORTC.5 'TRANSMITTER NUMBER THREE BUTTON
    GENDOOR VAR PORTA.5 'GENERATOR DOOR INPUT (-)
    SIDEDOOR VAR PORTA.4 'SIDE DOOR INPUT (-)
    SHOCKSENS VAR PORTC.3 'SHOCK SENSOR INPUT (INTERNAL)
    KEYSWITCH VAR PORTA.0 'KEY SWITCH INPUT FOR ARM/DISARM
    LED VAR PORTC.4 'LED OUTPUT
    NOTRIGSD VAR BYTE 'NO TRIGGER SIDE DOOR-3 TIMES MAX
    NOTRIGGD VAR BYTE 'NO TRIGGER GENERATOR DOOR-3 TIMES MAX
    NOTRIGSS VAR BYTE 'NO TRIGGER SHOCK SENSOR-3 TIMES MAX
    SD VAR BYTE 'SIDE DOOR VARIABLE-COUNTS NUMBER OF TIMES
    THE SIDE DOOR HAS BEEN SET OFF
    SS VAR BYTE 'SHOCK SENSOR VARIABLE-COUNTS NUMBER OF TIMES
    THE SIDE DOOR HAS BEEN SET OFF
    GD VAR BYTE 'GENERATOR DOOR VARIABLE-COUNTS NUMBER OF
    TIMES THE SIDE DOOR HAS BEEN SET OFF
    GENDOORNT VAR BYTE 'THIS VARIABLE WILL BE SET TO ONE IF THE
    GENERATOR DOOR IS OPEN WHEN SETTING THE ALARM.
    SD=0 'SET SD TO 0
    SS=0 'SET SS TO 0
    GD=0 'SET GD TO 0
    NOTRIGSD=0 'SET NOTRIGSD TO 0
    NOTRIGSS=0 'SET NOTRIGSS TO 0
    NOTRIGGD=0 'SET NOTRIGGD TO 0
    GENDOORNT=0 'SET GENDOORNT TO 0
    X VAR BYTE 'VARIABLE COUNTER USED THROUGHOUT THE PROGRAM
    T VAR WORD 'TIMER VARIABLE USED TO TIME THE ALARM FUNCTION
    L VAR WORD 'LED COUNTER
    X=0 'VARIABLE COUNTER
    T=0 'VARIABLE COUNTER
    L=0 'LED TIMER
    LOW LIGHTS 'SET LIGHT RELAY TO OFF
    LOW BRAKESO 'SET BRAKE/SIREN RELAY TO OFF
    LOW led 'ENSURE ALARM LED IS OFF
    '------------------------------START OF
    PROGRAM---------------------------------
    PAUSE 1000
    START:
    IF BUTTON1=1 OR BUTTON2=1 OR BUTTON3=1 THEN GOTO ARM
    IF KEYSWITCH=0 THEN GOTO ARM
    GOTO START

    OK, so here is my problem....The customer tells me that if he quickly
    applies power and then reapplies it (less than 1 second) a bunch of times that sometimes the relays will become activated. Now, I know the worst things for electronics, other than heat, is to take power off and then reapply
    it quickly so this is a concern. He also tells me that sometimes the
    outputs will stay latched and he has to cycle the power a few times
    or just leave it off in order to reset it.

    Here are my questions. Do you think if I increase the pause at the
    beginning of the program that this would solve the problem? I changed
    the PWRT and WDT commands to off because sometimes the voltage sagged
    below the threshold and reset the device. Do you think this has
    something to do with it? The last question I have is, do you think I
    should add a big output capacitor to smooth the spikes? Would this
    possibly solve the problem? I currently do not have an ouput
    capacitor other than the .1uF for noise.

    Thanks in advance for your help.

    Chris

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Christopher4187, I for one would set the output ports used for relays and lights to an off default state before I set the direction registers. Also make sure that the interface you use (what ever it may be) also has a default state before power is applied, Ie pulldown resistors on transistor bases and fet gates. This takes care of the undefined state of the outputs during the poweron time when the port pins of the micro are defaulted as inputs. Also make sure you are setting the initial states of variables used in computations for the outputs. I always use the CLEAR directive and then set the initial states of the variables. If you do these things you will not have the random output states you are talking of.

    Dave Purola,
    N8NTA

Similar Threads

  1. Gerber - PCB Layout Software??
    By kevj in forum General
    Replies: 10
    Last Post: - 3rd April 2013, 06:51
  2. Keylogger software
    By Christopher4187 in forum Off Topic
    Replies: 3
    Last Post: - 5th June 2008, 14:58
  3. Software Stack
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 10:04
  4. Replies: 3
    Last Post: - 26th November 2006, 21:47
  5. pic software
    By Darrenmac in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th December 2005, 07:08

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