Problem with new release

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 12:16 am

Hello,
since the last update I have encountered 2 problems, one relating to the timer and the other in a module that I use for a button verification.
I have attached 2 zip with assembly and full list generated with latest and previous version.

Problem 1
On PORTA.1 I have a led with two different periods of on and off and will never come on.
If I put a single TOGGLE (PORTA.1) in OnTimer SUB it works, if I add the counters and check on status directly not working and never lights up.

Problem 2
On PORTB.4 have a pullup resistor and a button to gnd if test in main loop the state of PORTB.4 directly usart report "Pressed" when use the module "Button.BAS" nothing happens.

I reproduced both of these problems in the program and a module below:

Code: Select all

   Device  = 18F4685
   Clock   = 40

 
Include "Config_V3_NOWDT.bas"
Include "ISRTimer.bas"
#option BTN1_PIN = PORTB.4
Include "button"
Include "usart"

Dim HLTH_PIN        As PORTA.1              
Dim HealthOn        As Integer              // led on cycles 
Dim HealthOff       As Integer              //  led off cycles 
Const  Timer1 = 0                              //  flashing timer

{
****************************************************************************
* Name    : OnTimer (PRIVATE)                                              *
****************************************************************************
} 
Private Sub OnTimer()
    If HLTH_PIN = 0 Then
        If HealthOff > 200 Then 
            High(HLTH_PIN)
            HealthOff   = 0
            HealthOn    = 0
        Else
            Inc(HealthOff)
        End If                    
    Else
        If HealthOn > 10 Then 
            Low(HLTH_PIN)
            HealthOff   = 0
            HealthOn    = 0
        Else
            Inc(HealthOn)
        End If                            
    End If  
End Sub

{
****************************************************************************
* Name    : Initialize (PRIVATE)                                            *
****************************************************************************
}
Private Sub Initialize()
    Output(HLTH_PIN)        // Health Led

    HealthOff   = 0
    HealthOn    = 0  

    Timer.Initialize(1)
    Timer.Items(Timer1).Interval = 10        // 10ms
    Timer.Items(Timer1).OnTimer = @OnTimer   // timer event handler
    Timer.Items(Timer1).Enabled = true
    Timer.Start

    USART.SetBaudrate(br115200)
    DelayMS(1000)
End Sub

Initialize()
Stato = False

While 1 = 1

    If IsP1Pressed() Then
        USART.Write("Pressed",13,10)
    End If  


'    if PORTB.4 = 0 then
'        usart.write("Pressed",13,10)
'    end if
Wend

Module "Button.BAS"

Code: Select all

Module Button 

#if IsOption(BTN1_PIN) And Not IsValidPortPin(BTN1_PIN) 
   #error BTN1_PIN, "Invalid option. BTN1_PIN must be a valid port pin."
#endif
#option BTN1_PIN = PORTB.4

#if isoption(COMMON_PRESS_CYCLES) 
   Const cCommonCycle As Integer = COMMON_PRESS_CYCLES
#else
   Const cCommonCycle As Integer = 100
#endif


Dim
   bBTN1_PIN As BTN1_PIN.BTN1_PIN@

Private Dim lastP1 As Boolean
Private Dim testP1 As Integer

{
****************************************************************************
* Name    : IsP1Pressed (PUBLIC)                                           *
****************************************************************************
} 
Public Function IsP1Pressed() As Boolean
    result = false
    If testP1 > cCommonCycle Then
        If bBTN1_PIN = 0 Then 
            If lastP1 = false Then 
                lastP1  = true
                result  = true
            End If
        Else
            lastP1 = false
        End If    
        testP1 = 0
    Else
        Inc(testP1)
    End If
End Function

{
****************************************************************************
* Name    : Initialize (PRIVATE)                                           *
* Purpose :                                                                *  
****************************************************************************
} 
Private Sub Initialize()
    Input(bBTN1_PIN)       
    lastP1 = false
    testP1 = 0
End Sub
    
Initialize()    
Module "Config_V3_NOWDT.bas"

Code: Select all

Module Config_V3_NOWDT

#if _Device in (18F4685,18F2682)
    Config
            OSC = HSPLL,
            PWRT = On,
            WDT = off, 
            WDTPS = 32768,
            MCLRE = off,
            LVP = OFF,
            PBADEN = OFF,
            STVREN = off,  
#if isoption(PROTECT) And PROTECT = true
            CP0 = On, 
            CP1 = On,
            CP2 = On,
            CP3 = On,
            CP4 = On,
#if _device = 18F4685            
            CP5 = On,
#endif
            EBTR0 = On,
            EBTR1 = On,
            EBTR2 = On,
            EBTR3 = On,
            EBTR4 = On,
#if _device = 18F4685            
            EBTR5 = On,
#endif
            CPD = On,
            CPB = On,     
#else
            CP0 = off, 
#endif
            BOREN  = off   
#else
    #error "Invalid device for HSPLL." 
#endif
 
 Include "SetDigitalIO.bas"
 SetAllDigital()
Attachments
After-Upgrade.zip
(55.14 KiB) Downloaded 209 times
Before-Upgrade.zip
(55.28 KiB) Downloaded 221 times

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 10:52 am

I think it may be a problem with the inc() operator on a signed value - can you replace inc() with <var> = <var> + 1 and let me know if it fixes the problem for you.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 3:31 pm

Thanks David,
indeed changing from INC (<value>) to <value> = <value> +1 and the part relating to SUB OnTimer now works perfectly.
I modified this way also Button.IsP1Pressed () but now I have the opposite and strange problem that is despite the pullup relative to the button bit of PORTB.4 is always seen to 0 (as if it were pressed) and then the main loop return a "Pressed".
If I disable the timer by commenting setting lines this problem of false reading PORTB.4 not happen.
Let me investigate a moment but is not due to the HW because I rebuilt this routines with the previous version and it works as it should..
For the sake I brought the contents of the procedure OnTimer () within an external module but PORTB.4 is read to 0 when OnTimer() is enabled and invoked because the message status "Pressed" appears in RS232 exactly at change status of the LED.
Now I doubt they're coming on module SetAllDigital () but I tried to pass by Utils module and recompiling with the two versions of the compiler, but the result does not change PORTB.4 is seen at 0 enabling the timer only with the latest version .

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 3:54 pm

I can't see what might have caused problems in the last update, apart from the inc() anomaly with signed numbers. Can you keep me informed of progress with respect to your investigation - I have fixed the inc() problem but will delay the online update until you report back...

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: Problem with new release

Post by Jerry Messina » Sun Nov 16, 2014 4:34 pm

Excuse me for butting in, but I may have found an issue...

When I change the OnTimer routine to remove the 'inc()' statements, it uses a temp frame variable to do the incrementing...

Code: Select all

?I000053_F000_000029_P000059 ; L#MK HEALTHOFF = HEALTHOFF + 1
    CLRF F0_S16H,0				; << FRAME VARIABLE
    MOVLW 1
    MOVWF F0_S16,0
    MOVF F0_S16,0,0
    ADDWF M47_S16,1
    MOVF F0_S16H,0,0
    ADDWFC M47_S16H,1

?I000058_F000_000038_P000059 ; L#MK HEALTHON = HEALTHON + 1
    CLRF F0_S16H,0				; << FRAME VARIABLE
    MOVLW 1
    MOVWF F0_S16,0
    MOVF F0_S16,0,0
    ADDWF M45_S16,1
    MOVF F0_S16H,0,0
    ADDWFC M45_S16H,1
Likewise, when I changed IsP1Pressed to remove inc(), I got:

Code: Select all

?I000025_F005_000040_P000009 ; L#MK TESTP1 = TESTP1 + 1
    CLRF F1_S16H,0				; << FRAME VARIABLE
    MOVLW 1
    MOVWF F1_S16,0
    MOVF F1_S16,0,0
    ADDWF M42_S16,1
    MOVF F1_S16H,0,0
    ADDWFC M42_S16H,1
Looking at the asm file, it seems that the two frame variables partially overlay each other (EQU 26)

Code: Select all

F0_S16 EQU 25
F0_S16H EQU 26

F1_S16 EQU 26
F1_S16H EQU 27
If I follow the logic correctly, the OnTimer() is executed in the timer ISR, and IsP1Pressed() is in the main context, so these two frame variables can't be overlayed.

The previous version (sf2222) didn't use temps when it incremented an integer
Attachments
sftest9.zip
(1.79 KiB) Downloaded 221 times
Last edited by Jerry Messina on Sun Nov 16, 2014 4:50 pm, edited 1 time in total.
Reason: add src files

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 5:59 pm

If you are assigning a sub as a pointer, the frame requirements are totally non-deterministic at compile time. If using pointers in this way, they should always be declared as events. This will ensure they get their own unique stack allocation. Sub and function stacks are recycled. For example,

Code: Select all

Event OnTimer()
   ...
End Event
...
Timer.Items(Timer1).OnTimer = @OnTimer
Try changing to "event" and let me know if this fixes the problem for you...

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 6:12 pm

David I can confirm that same hardware using both earlier libraries as the updated the result is the same: compiler version before have no problem at PORTB.4

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 6:26 pm

Can you post your before and after *.asm files again, using <var> = <var> + 1 and changing OnTimer() to event. I really cannot see why it is not working for you at the moment...

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 6:27 pm

David your statement is correct, turning OnTimer into event does not affect the PORTB.4 and is not found in 0.
But against the pressure button is never detected by isP1Pressed ().

Code: Select all

Event OnTimer()
    If HLTH_PIN = 0 Then
        If HealthOff > 5 Then 
            High(HLTH_PIN)
            HealthOff   = 0
            HealthOn    = 0
        Else
            HealthOff = HealthOff + 1 
        End If                    
    Else
        If HealthOn > 2 Then 
            Low(HLTH_PIN)
            HealthOff   = 0
            HealthOn    = 0
        Else
            HealthOn = HealthOn + 1 
        End If                            
    End If  
End Event

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 6:35 pm

David the zip before and after compiled with the event.
Attachments
After-wEvent.zip
(55.44 KiB) Downloaded 216 times
Before-wEvent.zip
(55.38 KiB) Downloaded 207 times

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 6:41 pm

Comparing the *.asm, you still have a inc(testP1) statement. Can you change *all*of the inc() statements in your program. Then re-test. If it still does not work, recompile and then attach before and after.

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 6:53 pm

Great job, David.
The problem is that I had two sources with the same name for the form Button.bas ... always the same problem and I was careful to say that there.
However I have created two zip.
Attachments
Before-wEvent-and-button2.zip
(55.23 KiB) Downloaded 221 times
After-wEvent-and-button2.zip
(55.53 KiB) Downloaded 225 times

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 6:55 pm

So it has fixed your problem?

User avatar
Coccoliso
Posts: 152
Joined: Mon Feb 17, 2014 10:34 am

Re: Problem with new release

Post by Coccoliso » Sun Nov 16, 2014 6:58 pm

Yes!

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Re: Problem with new release

Post by David Barker » Sun Nov 16, 2014 7:04 pm

Great! Now download a new BETA (B1) from here

http://www.sfcompiler.co.uk/downloads/beta/

and then try enabling the inc() statements again. Let me know if this version fixes the inc() problems for you.

Post Reply