Many problems with programs that used to work


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116

    Default Many problems with programs that used to work

    Hi,

    I am having troubles recently. Programs that used to work ok are now behaving strangely, like certain lines of code being ignored, or so it seems. I may have only changed a pause time or something simple, but when compiled no longer work as expected. This started (though may be a coincidence) when I moved to windows 7 at work, PBP V2.5 did not seem to work, so I upgraded to PBP3, but still having problems. Here is an example.
    Code:
    goto start
    pulse:
    while pulseon = 1
    high pulses
    pauseus 100
    low pulses
    pauseus 100
    wend
    return
    
    start:
    if coil1 = 1 then
    thy1 = 1
    thy2 = 0
    thy3 = 0
    thy4 = 0
    endif
    
    if coil2 = 1 then
    thy1 = 0
    thy2 = 1
    thy3 = 0
    thy4 = 0
    endif
    
    if coil3 = 1 then
    thy1 = 0
    thy2 = 0
    thy3 = 1
    thy4 = 0
    endif
    
    if coil4 = 1 then
    thy1 = 0
    thy2 = 0
    thy3 = 0
    thy4 = 1
    endif
    
    if pulseon = 1 then gosub pulse
    
    goto start
    Now no matter which coil input is high, and when pulseon is low all the program will do is switch on thy1, and continually run the pulse subroutine.
    Here is another:
    Code:
    if lastgun = 3 then goto jmp3   'if it was last to be used then no need to 
                                              'send settings or change relays
    high coil3     ;switch on channel 3 relay
    low coil1     ;swirch off all others
    low coil2
    low coil4
    'load channel 3 settings ready to be sent to main card
    let ivalue = current3
    let tvalue = time3
    let gvalue = gas3
    let scvalue = sctime3
    gosub sendmain ' send the values
    pause 150
    jmp3:   'jump to here if this was last gun used
    let lastgun = 3 'set last gun flag
    Here the first line is always ignored, all of the rest of this quite large program works fine, and these programs used to work fine.
    I have tried changing chips, and PCBs so I know it cant be hardware faults, or blown chips.
    Anyone have any ideas?

    Regards
    Bob.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Hi, Bob

    one of PBP3 main changes is the CONFIG section change ...

    so, if you had shown us a FULL listing, probably we could have helped you some more ...

    BTW, I do not see any initialization section nor ... is "omission" decided by you ???

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Whenever I see several HIGH/LOW etc in a row I suspect Read-Modify-Write issue.
    Try inserting a Pause 10 between each row and see what happends. Also make sure you have analog functions (ADC and comparator) disabled on all pins since they will otherwise interfere.
    If it doesn't seem to help please also let us know which chip you're using.

    /Henrik.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Hi, Henrik

    I suppose you meant :
    Code:
    if coil1 = 1 then
    thy1 = 1
    thy2 = 0
    thy3 = 0
    thy4 = 0
    endif
    because there are no RMW issue when using HIGH and LOW ( as they include a TRIS command that takes some time ) ... tested "in live" with 3.5 µF loads ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    I meant those too.
    I know HIGH/LOW includes the clearing the TRIS-bit and that it's less likely to get a RMW-issue using it. I probably wouldn't go so far to say that RMW is non existent though since it depends on the load and, obviously, on the clock frequency. What frequency did you run at when you tried a 3.5uF capacitve load? RMW-issues also exists (with and without HIGH/LOW) when the pin(s) isn't properly configured for digital I/O.

    /Henrik.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Quote Originally Posted by HenrikOlsson View Post
    . What frequency did you run at when you tried a 3.5uF capacitve load? /Henrik.
    not more than 32 Mhz with a 16F628 and 80 Mhz with 18F chips ( NOT using LAT ! ) ... yess ! I made some hard overclocking tests ..

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  7. #7
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,610


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Well, in that case I stand corrected - for now... :-)

    /Henrik.

  8. #8
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Hi,

    Thank you for your help. I will post the full code.

    Code:
    #config
     __config _HS_OSC & _WDT_ON & _PWRTE_ON & _BOREN_ON & _CP_ON & _LVP_OFF
    #ENDCONFIG
    
    data @1,200,0,200,0,200,0,200,0,50,0,50,0,50,0,50,0
    data @17,0,0,0,0,0,0,0,0,30,0,30,0,30,0,30,0,0
    define OSC 20
    
    asm
        BSF     STATUS, RP0 ;SELECT BANK 1
        MOVLW   0x06        ;A/D channels all digital
        MOVWF   ADCON1
        MOVLW   0x07        ;PORT B = 00000111
        MOVWF   TRISB
        MOVLW   0xEF        ;PORT C = 11101111
        MOVWF   TRISC
        MOVLW   0x0F        ;PORT D = 00001111
        MOVWF   TRISD
        MOVLW   0x07        ;PORT E = 111
        MOVWF   TRISE
        BCF     STATUS, RP0 ;SELECT BANK 0    
    ENDASM     
    
    spare       var portb.0
    coilin      var portb.1
    contact     var portb.2
    pulseon     var portb.3
    coil1       var portb.4
    coil2       var portb.5
    coil3       var portb.6
    coil4       var portb.7
    sw4         var portc.0
    sw3         var portc.1
    sw2         var portc.2
    sw1         var portc.3
    trigout     var portc.4
    trigger4    var portd.0
    trigger3    var portd.1
    trigger2    var portd.2
    trigger1    var portd.3
    led1        var portd.4
    led2        var portd.5
    led3        var portd.6
    led4        var portd.7
    clock       var porte.0
    dout        var porte.1
    send        var porte.2
    
    current1    var word
    current2    var word
    current3    var word
    current4    var word
    time1       var word
    time2       var word
    time3       var word
    time4       var word
    gas1        var word
    gas2        var word
    gas3        var word
    gas4        var word
    sctime1     var word
    sctime2     var word
    sctime3     var word
    sctime4     var word
    packet      var word
    index       var word
    ivalue      var word
    tvalue      var word
    gvalue      var word
    scvalue     var word
    machinetype var word
    lastgun     var byte
    let lastgun = 0
    GOSUB readvalues
    GOTO MAIN
    
    writevalues1:           'write gun 1 values to memory
    write 1, ivalue.lowbyte
    write 2, ivalue.highbyte
    write 9, tvalue.lowbyte
    write 10, tvalue.highbyte
    write 17, gvalue.lowbyte
    write 18, gvalue.highbyte
    write 25, scvalue.lowbyte
    write 26, scvalue.highbyte
    return
    writevalues2:           'write gun 2 values to memory
    write 3, ivalue.lowbyte
    write 4, ivalue.highbyte
    write 11, tvalue.lowbyte
    write 12, tvalue.highbyte
    write 19, gvalue.lowbyte
    write 20, gvalue.highbyte
    write 27, scvalue.lowbyte
    write 28, scvalue.highbyte
    return
    writevalues3:           'write gun 3 values to memory
    write 5, ivalue.lowbyte
    write 6, ivalue.highbyte
    write 13, tvalue.lowbyte
    write 14, tvalue.highbyte
    write 21, gvalue.lowbyte
    write 22, gvalue.highbyte
    write 29, scvalue.lowbyte
    write 30, scvalue.highbyte
    return
    writevalues4:           'write gun 4 values to memory
    write 7, ivalue.lowbyte
    write 8, ivalue.highbyte
    write 15, tvalue.lowbyte
    write 16, tvalue.highbyte
    write 23, gvalue.lowbyte
    write 24, gvalue.highbyte
    write 31, scvalue.lowbyte
    write 32, scvalue.highbyte
    return
    
    readvalues:
    read 1, current1.lowbyte
    read 2, current1.highbyte
    read 3, current2.lowbyte
    read 4, current2.highbyte
    read 5, current3.lowbyte
    read 6, current3.highbyte
    read 7, current4.lowbyte
    read 8, current4.highbyte
    read 9, time1.lowbyte
    read 10, time1.highbyte
    read 11, time2.lowbyte
    read 12, time2.highbyte
    read 13, time3.lowbyte
    read 14, time3.highbyte
    read 15, time4.lowbyte
    read 16, time4.highbyte
    read 17, gas1.lowbyte
    read 18, gas1.highbyte
    read 19, gas2.lowbyte
    read 20, gas2.highbyte
    read 21, gas3.lowbyte
    read 22, gas3.highbyte
    read 23, gas4.lowbyte
    read 24, gas4.highbyte
    read 25, sctime1.lowbyte
    read 26, sctime1.highbyte
    read 27, sctime2.lowbyte
    read 28, sctime2.highbyte
    read 29, sctime3.lowbyte
    read 30, sctime3.highbyte
    read 31, sctime4.lowbyte
    read 32, sctime4.highbyte
    READ 33, MACHINETYPE.LOWBYTE
    READ 34, MACHINETYPE.HIGHBYTE
    return
    
    sendmain:
    low clock
    low dout
    low send
    let packet = ivalue
    high send
    pause 50
    gosub sout
    low send
    pause 10
    let packet = tvalue
    high send
    pause 10
    gosub sout
    low send
    pause 10
    let packet = gvalue
    high send
    pause 10
    gosub sout
    low send
    pause 10
    let packet = scvalue
    high send
    pause 10
    gosub sout
    low send
    pause 10
    let packet = machinetype
    high send
    pause 10
    gosub sout
    low send
    pause 5
    input send
    input clock
    input dout
    return
    
    sout:
    for index = 0 to 15
    dout = packet.0[index]
    pause 5
    high clock
    pause 5
    low clock
    pause 5
    next index
    low dout
    return
    
    weld1: 'welding routine for gun1
    'check if it is a good trigger signal
    pause 10
    if trigger1 = 1 then return
    pause 10
    if trigger1 = 1 then return
    'check to see if gun1 was last to be uesd
    if lastgun = 1 then goto jmp1   'if it was last to be used then no need to 
                                    'send settings or change relays
    high coil1     ;switch on channel 1 relay
    low coil2     ;swirch off all others
    low coil3
    low coil4
    'load channel 1 settings ready to be sent to main card
    let ivalue = current1
    let tvalue = time1
    let gvalue = gas1
    let scvalue = sctime1
    gosub sendmain ' send the values
    pause 150
    jmp1:   'jump to here if this was last gun used
    let lastgun = 1 'set last gun flag
    high pulseon
    pause 150
    high trigout
    pause 100
    low trigout
    pause gas1
    pause time1
    pause sctime1
    asm
    JMPA    BTFSC   _coilin     ;wait for coil to go low
            GOTO    JMPA
    JMPB    BTFSC   _contact    ;wait for break in contact
            GOTO    JMPB
    endasm 
    low pulseon
    pause 600
    return
    
    weld2: 'welding routine for gun2
    'check if it is a good trigger signal
    pause 10
    if trigger2 = 1 then return
    pause 10
    if trigger2 = 1 then return
    'check to see if gun2 was last to be uesd
    if lastgun = 2 then goto jmp2   'if it was last to be used then no need to 
                                    'send settings or change relays
    high coil2     ;switch on channel 2 relay
    low coil1     ;swirch off all others
    low coil3
    low coil4
    'load channel 2 settings ready to be sent to main card
    let ivalue = current2
    let tvalue = time2
    let gvalue = gas2
    let scvalue = sctime2
    gosub sendmain ' send the values
    pause 150
    jmp2:   'jump to here if this was last gun used
    let lastgun = 2 'set last gun flag
    high pulseon
    pause 150
    high trigout
    pause 100
    low trigout
    pause gas2
    pause time2
    pause sctime2
    asm
    JMPC    BTFSC   _coilin     ;wait for coil to go low
            GOTO    JMPC
    JMPD    BTFSC   _contact    ;wait for break in contact
            GOTO    JMPD
    endasm 
    low pulseon
    pause 600  
    return
    
    weld3: 'welding routine for gun3
    'check if it is a good trigger signal
    pause 10
    if trigger3 = 1 then return
    pause 10
    if trigger3 = 1 then return
    'check to see if gun3 was last to be uesd
    if lastgun = 3 then goto jmp3   'if it was last to be used then no need to 
                                    'send settings or change relays
    high coil3     ;switch on channel 3 relay
    low coil1     ;swirch off all others
    low coil2
    low coil4
    'load channel 3 settings ready to be sent to main card
    let ivalue = current3
    let tvalue = time3
    let gvalue = gas3
    let scvalue = sctime3
    gosub sendmain ' send the values
    pause 150
    jmp3:   'jump to here if this was last gun used
    let lastgun = 3 'set last gun flag
    high pulseon
    pause 150
    high trigout
    pause 100
    low trigout
    pause gas3
    pause time3
    pause sctime3
    asm
    JMPE    BTFSC   _coilin     ;wait for coil to go low
            GOTO    JMPE
    JMPF    BTFSC   _contact    ;wait for break in contact
            GOTO    JMPF
    endasm     
    low pulseon
    pause 600
    return  
    
    weld4: 'welding routine for gun4
    'check if it is a good trigger signal
    pause 10
    if trigger4 = 1 then return
    pause 10
    if trigger4 = 1 then return
    'check to see if gun4 was last to be uesd
    if lastgun = 4 then goto jmp4   'if it was last to be used then no need to 
                                    'send settings or change relays
    high coil4     ;switch on channel 4 relay
    low coil1     ;swirch off all others
    low coil2
    low coil3
    'load channel 4 settings ready to be sent to main card
    let ivalue = current4
    let tvalue = time4
    let gvalue = gas4
    let scvalue = sctime4
    gosub sendmain ' send the values
    pause 150
    jmp4:   'jump to here if this was last gun used
    let lastgun = 4 'set last gun flag
    high pulseon
    pause 150
    high trigout
    pause 100
    low trigout
    pause gas4
    pause time4
    pause sctime4
    asm
    JMPG    BTFSC   _coilin     ;wait for coil to go low
            GOTO    JMPG
    JMPH    BTFSC   _contact    ;wait for break in contact
            GOTO    JMPH
    endasm     
    low pulseon
    pause 600
    return
    
    settings:
    'test switches & light the ones that need to be on
    if sw1 = 0 then
    high led1
    else
    low led1
    endif
    if sw2 = 0 then
    high led2
    else
    low led2
    endif
    if sw3 = 0 then
    high led3
    else
    low led3
    endif
    if sw4 = 0 then
    high led4
    else
    low led4
    endif
    'if all switches are off (high) then turn off leds, and return
    if (sw1 = 1) and (sw2 = 1) and (sw3 = 1) and (sw4 = 1) then 
    low led1
    low led2
    low led3
    low led4
    return
    endif
    if send = 1 then gosub readin
    goto settings
    
    rcv:  'routine to receive packets of information
    for index = 0 to 15
    while clock = 0
    wend
    packet.0[index] = dout
    while clock = 1
    wend
    next index
    return
    
    readin:
    pause 1
    if send = 0 then return
    pause 1
    if send = 0 then return
    pause 1
    if send = 0 then return
    pause 1
    if send = 0 then return
    pause 1
    if send = 0 then return
    pause 1
    if send = 0 then return
    gosub rcv
    let ivalue = packet
    let packet = 0
    ASm
    JMPI    BTFSC   _send  ;Wait for send to go low
            GOTO    JMPI
    JMPJ    BTFSS   _send  ;Wait for send to go high
            GOTO    JMPJ
    ENDASM        
    gosub rcv
    let tvalue = packet
    let packet = 0
    ASm
    JMPK    BTFSC   _send  ;Wait for send to go low
            GOTO    JMPK
    JMPL    BTFSS   _send  ;Wait for send to go high
            GOTO    JMPL
    ENDASM  
    gosub rcv
    let gvalue = packet
    let packet = 0
    ASm
    JMPM    BTFSC   _send  ;Wait for send to go low
            GOTO    JMPM
    JMPN    BTFSS   _send  ;Wait for send to go high
            GOTO    JMPN
    ENDASM  
    gosub rcv
    let scvalue = packet
    let packet = 0
    ASm
    JMPO    BTFSC   _send  ;Wait for send to go low
            GOTO    JMPO
    JMPP    BTFSS   _send  ;Wait for send to go high
            GOTO    JMPP
    ENDASM  
    gosub rcv
    let machinetype = packet
    let packet = 0
    ASM
    JMPQ    BTFSC   _send  ;Wait for send to go low
            GOTO    JMPQ
    ENDASM        
    'we have received values from front PCB, now need to store any that
    'have switches set
    if led1 = 1 then gosub writevalues1
    if led2 = 1 then gosub writevalues2
    if led3 = 1 then gosub writevalues3
    if led4 = 1 then gosub writevalues4
    write 33, machinetype.lowbyte
    write 34, machinetype.highbyte
    return
    
    main:
    'first check for any trigger signals
    if trigger1 = 0 then gosub weld1
    if trigger2 = 0 then gosub weld2
    if trigger3 = 0 then gosub weld3
    if trigger4 = 0 then gosub weld4
    'now check if any settings switches are on
    if (sw1 = 0) or (sw2 = 0) or (sw3 = 0) or (sw4 = 0) then gosub settings
    'switch on led of last used gun
    if lastgun = 1 then 
    high led1
    low led2
    low led3
    low led4
    endif
    if lastgun = 2 then
    low led1
    high led2
    low led3
    low led4
    endif
    if lastgun = 3 then
    low led1
    low led2
    high led3
    low led4
    endif
    if lastgun = 4 then
    low led1
    low led2
    low led3
    high led4
    endif
    goto main
    end
    I'm not sure if this will help, as I said the program did work fine, before Windows 7, and PBP3. Though I am not certain that this is the cause. My development time is short and fragmented with months going by without looking at a project. This makes it hard to keep track of what stage I was at, and what exactly I was doing when I encountered a problem.

    The problem with this program is in the 4 weld subroutines. The If lastgun statements (in bold type) are always ignored, or rather if you keep pressing the trigger on one gun the lastgun flag is not set to a number, so the next time pressing the trigger the code i want to skip is always executed.

    Regards
    Bob.

  9. #9
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    When I get unexpected results like this, I test pieces of logic one by one.

    I'd start with just blinking a led in simplest loop possible; just to be sure pic timing and configs are correct. With timing you can verify easily, like:

    LOOP:
    pin=1
    pause 1000
    pin=0
    pause 1000
    goto LOOP

    Robert
    Last edited by Demon; - 22nd March 2013 at 01:41. Reason: example

  10. #10
    Join Date
    Feb 2005
    Location
    Holmfirth England
    Posts
    116


    Did you find this post helpful? Yes | No

    Default Re: Many problems with programs that used to work

    Hi,

    Thanks for your replies. I have now solved the problem, but still cant explain why it was behaving as it was.
    Turns out that I had added some code that had not been tested, before being broken off the project for some months.

    asm
    JMPA BTFSC _coilin ;wait for coil to go low
    GOTO JMPA
    JMPB BTFSC _contact ;wait for break in contact
    GOTO JMPB
    endasm

    They should have been BTFSS. Though how the program was still running and not getting stuck there is a mystery to me. I think it may have been some issue that caused the pic to do a brown out reset each time it went through a weld routine.

    Anyways now I have everything working like a dream the project has been scrapped, so sorry for wasting all of your time.

    Kind regards
    Bob.

Similar Threads

  1. lost programs/programs rolled back
    By Chris Barron in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 10th February 2010, 00:22
  2. How to use TRIS on a ICD programs
    By timseven in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 10th August 2009, 01:12
  3. HELP W/programs
    By furmpf in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th February 2008, 13:45
  4. problems with I2C.... and ideas why dosent work?
    By snood in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 26th April 2005, 12:54
  5. Replies: 3
    Last Post: - 3rd September 2003, 12:05

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