Issue with 16F88 startup


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2010
    Posts
    27

    Default Issue with 16F88 startup

    I wrote this app, which appears to function with the exception of powerup. The Hi setpoint appears to get set, but I never see the delays or the splash screen, I start out seeing main loop on the screen. I added delays and never could make it go away. Anyone else have this issue?
    ' Name : blink_Serial_test.pbp
    ' Compiler : PICBASIC PRO Compiler 2.6
    ' Assembler : PM or MPASM
    ' Target PIC : 16F or 18F types
    ' Hardware : Non specific
    ' Oscillator : internal or external
    ' Keywords : BLINK LED
    ' Description : PICBASIC PRO program to to blink an LED and write to a screen
    ' connectedto PORTB.7 about once a second
    '

    'The following program is a simple test to blink an LED on and off and write to
    'a screen the color LED being blinked. Select a
    'device in the dropdown list above, then click the Compile Only button on the
    'toolbar to compile the program and generate a hex file.
    'THIS FILE USES THE INTERNAL OSCILLATOR!

    ' Configure pins for digital operation (uncomment as needed).
    ' These settings are intended as simple examples. For more detail,
    ' see the appropriate device datasheet for register descriptions.
    'ANSEL = %00000000 ' 16F88, 16F688, 16F690, 16F88x
    'ANSELH = %00000000 ' 16F690, 16F88x
    'ADCON1 = %00000111 ' 16F87x, 16F87xA, 18F452
    'ADCON1 = %00001111 ' 18F4620

    include "modedefs.bas"
    OSCCON=%01101000

    define osc 4
    DEFINE ADC_BITS 10
    DEFINE ADC_CLOCK 3
    DEFINE ADC_SAMPLEUS 50

    CMCON = 7 ' Disable analog comparator
    ANSEL = %00000011 'enable A0-A2 as Analog inputs
    ADCON1 = %10000000 'right justify
    OPTION_REG.7 = 0

    RED_LED VAR PORTB.2 ' Assign name "LED" to PORTB.2 - activity light
    Green_LED VAR PORTB.0 ' Assign name "LED" to PORTB.0 and start relay
    Yellow_LED VAR PORTB.1 ' Assign name "LED" to PORTB.1 and stop relay
    LCD var PORTB.7 ' Assign name "LCD" to PORTB.7
    AIN0 var word 'Battery Voltage
    AIN1 var word 'Start Time
    AIN2 var word 'Start Voltage

    Volts_0 var word 'Battery Voltage
    Volts_1 var word 'Start Time
    Volts_2 var word 'Start Voltage
    Start_Seconds var word
    HI_0 var BYTE
    LOW_0 var BYTE
    HI_1 var BYTE
    LOW_1 var BYTE
    HI_2 var BYTE
    LOW_2 var BYTE
    HI_SP var BYTE
    LOW_SP var BYTE

    Hi_Side var byte
    Low_side var byte
    temp var word
    temp1 var word
    temp2 var word
    Start_Try VAR byte
    Low_Volts_Count var byte
    Hi_Volt_SP var word
    ACvolts_In VAR PORTB.6
    ACvolts VAR BIT


    Powerup:
    High LCD
    Pause 100
    serout 7,n9600,[254,1]
    Pause 100
    serout 7,n9600,[254,1,"Covey Off Grid"]
    serout 7,n9600,[254,192," Monitor V0.5"]
    Hi_Volt_SP = 275 'Setpoint*10 to turn off Gen.
    HI_SP = Hi_Volt_SP/10
    LOW_SP = Hi_Volt_SP//10
    Pause 2000
    Low_Volts_Count = 0
    if PORTA.7 then Goto Mainloop 'for future setup jumper
    if NOT PORTA.7 then Goto Mainloop 'for future setup jumper

    Mainloop:
    serout 7,n9600,[254,1," Mainloop"]
    pause 100
    Start_Try = 0
    Low Green_LED
    low Yellow_LED
    High RED_LED ' Turn on LED connected to PORTB.0
    Pause 500
    Gosub Analog_In_0 'Battery Voltage
    pause 30
    Gosub Analog_In_1 'Start Time
    pause 30
    Gosub Analog_In_2 'Start Voltage
    pause 30

    Gosub Display_Stats
    Low RED_LED ' Turn off LED connected to PORTB.0

    if AIN0 < AIN2 then Low_Volts_Count = Low_Volts_Count+1

    if AIN0 < AIN2 then serout 7,n9600,[254,1," Low Volts Count"]
    if AIN0 < AIN2 then serout 7,n9600,[254,192," ",#Low_Volts_Count]
    pause 500
    if Low_Volts_Count >= 3 then Goto EngineStart
    if Low_Volts_Count < 3 then goto Mainloop

    Analog_In_0:
    serout 7,n9600,[254,1," Analog_In_0"]
    pause 100
    ADCIN 0, AIN0
    Volts_0=AIN0*50/51/2
    HI_0 = Volts_0/10
    LOW_0 = Volts_0//10
    Return

    Analog_In_1:
    serout 7,n9600,[254,1," Analog_In_1"]
    pause 100
    ADCIN 1, AIN1
    Volts_1=AIN1*50/51/2
    Start_Seconds=AIN1*50/51/2
    HI_1 = Volts_1/100
    LOW_1 = Volts_1//100
    Return

    Analog_In_2:
    serout 7,n9600,[254,1," Analog_In_2"]
    pause 100
    ADCIN 2, AIN2
    Volts_2=AIN2*50/51/2
    HI_2 = Volts_2/10
    LOW_2 = Volts_2//10
    Return

    Display_Stats:
    serout 7,n9600,[254,1," Display_Stats"]
    pause 500
    serout 7,n9600,[254,1]
    serout 7,n9600,[254,128,"Bat Volts =",#HI_0,".",#LOW_0]
    serout 7,n9600,[254,192,"Start Volts=",#HI_2,".",#LOW_2]
    Pause 2000
    serout 7,n9600,[254,1," Crank Sec=",#HI_1,".",#LOW_1]
    Pause 1000
    return

    EngineStart:
    ACvolts = ~ACvolts_In
    serout 7,n9600,[254,1," EngineStart"]
    pause 500
    Low_Volts_Count = 0
    If (ACvolts = 0 AND Start_Try < 3) THEN High Green_LED 'High Starter Relay
    serout 7,n9600,[254,1," Crank Sec=",#HI_1,".",#LOW_1]
    serout 7,n9600,[254,192,"Start Try# ", #Start_Try]
    Pause Start_Seconds*10 '5v ~ 5 seconds
    Low Green_LED 'Low Starter Relay
    Pause 10000 'pause to re-try starting
    If (ACvolts = 0 AND Start_Try < 3) THEN Start_Try = Start_Try +1
    If (ACvolts = 0 AND Start_Try < 3) THEN GOTO EngineStart
    IF (ACvolts = 0 AND Start_Try >= 3) THEN GOTO LockedOut
    If ACvolts = 1 THEN GOTO Charging

    LockedOut:
    serout 7,n9600,[254,1," LockedOut"]
    pause 500
    Low RED_LED ' Turn off LED connected to PORTB.2
    Pause 2000 ' Delay for .5 seconds
    High RED_LED ' Turn on LED connected to PORTB.2
    Pause 250 ' Delay for .5 seconds
    Low RED_LED ' Turn off LED connected to PORTB.2
    Pause 150 ' Delay for .5 seconds
    High RED_LED ' Turn on LED connected to PORTB.2
    Pause 250 ' Delay for .5 seconds
    Low RED_LED ' Turn off LED connected to PORTB.2
    Pause 150 ' Delay for .5 seconds
    High RED_LED ' Turn on LED connected to PORTB.2
    Pause 250 ' Delay for .5 seconds
    Low RED_LED ' Turn off LED connected to PORTB.2
    Pause 150 ' Delay for .5 seconds
    GOTO LockedOut

    Charging:
    ACvolts = ~ACvolts_In
    serout 7,n9600,[254,1,"Charging SP=",#HI_SP,".",#LOW_SP]
    serout 7,n9600,[254,192,"Bat Volts =",#HI_0,".",#LOW_0]
    pause 500
    High RED_LED ' Turn on LED connected to PORTB.2
    Pause 3000 ' Delay for .5 seconds
    Low RED_LED ' Turn off LED connected to PORTB.2
    Pause 3000 ' Delay for .5 seconds
    Gosub Analog_In_0 'Battery Voltage
    pause 30
    'Gosub Display_Stats
    If ACvolts = 0 and Volts_0 < Hi_Volt_SP-30 THEN GOTO LockedOut
    If ACvolts = 1 and Volts_0 < Hi_Volt_SP THEN GOTO Charging
    if Volts_0 > Hi_Volt_SP then Goto Stop_Generator

    Stop_Generator
    High Yellow_LED ' Turn on LED connected to PORTB.1 and stop relay
    Pause 10000
    Low Yellow_LED ' Turn off LED connected to PORTB.1 and stop relay
    Goto mainloop


    End

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


    Did you find this post helpful? Yes | No

    Default

    Try adding a
    PAUSE 2000
    before
    Powerup:

    Sometimes it takes a bit for the screen to initialize.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2010
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    Try adding a
    PAUSE 2000
    before
    Powerup:

    Sometimes it takes a bit for the screen to initialize.
    In one attempt, I created
    startup:
    Pause 5000

    All it did was piss off my serial display.

    I notice I'm at 1959k, quite near the page boundary, could this be a factor
    Also, I'm using the internal oscillator.

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Plcguy View Post
    ' Compiler : PICBASIC PRO Compiler 2.6
    ...
    define osc 4
    ...
    serout 7,n9600,[254,1,"Covey Off Grid"]
    Apply the P260a patch.
    http://melabs.com/support/patches.htm

    There was an error in 2.60 that affects SEROUT's baudrate when running 9600 at 4mhz.
    It was fixed in the patch.

    Or use SEROUT2 or DEBUG. They were not affected by the problem.
    DT

  5. #5
    Join Date
    Oct 2010
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    I spoke with ScottEdwards, the manufac of the serial display. They sent me an app note where you hold the data pin low during startup. I was following a basic stamp app note where they say to hold it high. Works fine now.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Did you already have PBP 2.60A then?
    DT

  7. #7
    Join Date
    Oct 2010
    Posts
    27


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Did you already have PBP 2.60A then?
    yes, I did

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