problem with compiler Mikrobasic PIC24 during interrupt context swich

General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
carniela
Posts: 2
Joined: 17 Sep 2021 11:25

problem with compiler Mikrobasic PIC24 during interrupt context swich

#1 Post by carniela » 17 Sep 2021 11:42

Hello
I found a big problem with compiler Mikrobasic PIC24 during interrupt context swich
If you save in main program a bit variabile can be corrupted by
interrupt routine.
Seem that bit variable is not save on stack, byte , word and lonword variable is not effected.

Follow is a test file ready to run on MikroBasic for workstation V7 with pic P24FJ256GB110 Mikromedia board
All pic 24F have this bug. using MIKROBASIC compiler

In the test software on function Test_bit() the local variable " dim bw as bit" result corrupted when interrupt occour during time that this function is executed.
Error is random and depend from probabilty that interupt occour durnig execution time of this routine.
Changin bw as byte solve the problem , or blocking timer interrupt during execution of this function .

follow test code

' * Project name:
' TESTBIT
'
' * Revision History:
' 2021
' - initial release
' * Description:
' TEST bit.
' Result will be shown on 320x240 TFT display
' * Test configuration:
' MCU: PIC24FJ256GB110
' http://ww1.microchip.com/downloads/en/D ... 39897c.pdf
' Dev.Board: mikroMMB for PIC24 Board
' http://www.mikroe.com/eng/products/view ... c24-board/
' Oscillator: HS-PLL 4x, 8.00000 MHz
' ac:TFT_display
' SW: mikroBasic 7.1 PRO for dsPIC30/33 and PIC24
' http://www.mikroe.com/eng/products/view ... and-pic24/
' * NOTES:
' - none.
' *

program TFT



' Declarations section
dim TFT_DataPort as char at LATE
TFT_RST as sbit at LATC1_bit
TFT_BLED as sbit at LATD2_bit
TFT_RS as sbit at LATB15_bit
TFT_CS as sbit at LATF12_bit
TFT_RD as sbit at LATD5_bit
TFT_WR as sbit at LATD4_bit
TFT_DataPort_Direction as char at TRISE
TFT_RST_Direction as sbit at TRISC1_bit
TFT_BLED_Direction as sbit at TRISD2_bit
TFT_RS_Direction as sbit at TRISB15_bit
TFT_CS_Direction as sbit at TRISF12_bit
TFT_RD_Direction as sbit at TRISD5_bit
TFT_WR_Direction as sbit at TRISD4_bit
' End TFT module connections

DIM led_red as byte
dim cpd as byte

SUB PROCEDURE Init_Timer

cpd=0
'PR1 = 31250 ' Freq oscillator 8Mhz /256/31250 = 1 second timer
'PR1 = 15625 ' Freq oscillator 8Mhz /256/15625 = 0.5 second timer
'PR1 = 18300 ' Freq corrected for 0.58 hz
PR1= 7181 ' freq correct for 2 hz

'IPC0.TIIP=5 set interupt priority
T1IP_0_bit=1
T1IP_1_bit=0
T1IP_2_bit=1

'T1CONbits.TCKPS = 0x03; //timer prescaler bits
TCKPS_0_bit=1
TCKPS_1_bit=1


TCS_bit=0

TSYNC_bit=0

' T1CONbits.TCS = 0; //using FOSC/2
' TCS_T1CON_bit=0


'IFS0bits.T1IF = 0; //reset interrupt flag
IFS0.T1IF = 0 'reset interrupt flag
'IEC0bits.T1IE = 1; //turn on the timer1 interrupt
IEC0.T1IE=1 'turn on the timer1 interrupt

T1CON.TON=1 'start the timer

END SUB



''************************************************************************
'' THIS ROUTINE HAVe THE PROBLEM
' THIS ROUTINE IS FOR TESt BUG ONLY
' ROUTIN GIVE IN INPUT A WORd NUMBER END RETURN THE SAMA VALUE
' Problem was discover using some similar routine to drive sofware SPI bus
' Variabile bw set to bit generate random error .....bit lose in CONTEX SWICH INTERUPT ?
' Variable bs set to byte resolve the error
' Mask timer interrupt also resolve the problem using IEC0.T1IE=0


sub function Test_bit(dim valore as word) as word

dim cic as word
dim dato as word
dim bw as bit ' ************** THIS IS THE PROBLEM
''dim bw as byte ' THIS SOLVE THE PROBLEM UNCOMMENT Line and Comment line above

'IEC0.T1IE=0 'turn off the timer1 interrupt before test bit shift
'if disable interurupt cycle is working
'if this function receive an interupt in the middle sometimes ir return wrong caluclation

for cic=1 to 15
bw=valore.B0
if(bw=1) then
dato=dato+0x8000
end if
dato=word(dato>>1)
valore=word(valore>>1)
next cic

'IEC0.T1IE=1 'turn on agian the timer1 at tye and of test bit shift
'if disable interurupt cycle is working

result=dato



end sub


sub procedure milli_250() iv IVT_ADDR_T1INTERRUPT ics ICS_AUTO

' dim mean_sample_a as longint
''dim ptrbuf as word
TMR1=0



led_red=led_red+1
LATD.12=0
LATD.0=0

if led_red >=2 then
led_red=0
LATD.12=1
LATD.0=1
end if

delay_us(150)


IFS0.T1IF=0 'reset the interrupt flag

end sub












'*********************************************************************/

main:

dim prova,pd as word
dim incremento as longint
dim messaggio as char[50]
dim counter as longword


AD1PCFGL = 0xFFFF
AD1PCFGH = 0xFFFF
Delay_ms(150)
TFT_Init_ILI9340_8bit(320,240)
TFT_Set_Default_Mode
TFT_Set_Font(@TFT_defaultFont, CL_White, FO_HORIZONTAL)

TFT_Fill_Screen(0)
Delay_ms(100)
TFT_Write_Text("BitTest with Interrupt",5,10)
TFT_Set_Pen(CL_Green, 3)
TFT_Rectangle(1, 1, 200, 30)


TRISD.12=0

Init_Timer()

prova=0
counter=40
while TRUE

if prova >= 511 then
prova =511
incremento=-1
end if

if prova = 0 then
prova =0
incremento=1
end if


pd=Test_bit(prova)
if pd<>prova then ' ******* test return word is equal to send word
TFT_Write_Text("Bit error send =",5,counter)
wordtohex(prova, messaggio)
Ltrim(messaggio)
TFT_Write_Text(messaggio,110,counter)
TFT_Write_Text(" compare =",150,counter)
wordtohex(pd, messaggio)
Ltrim(messaggio)
TFT_Write_Text(messaggio,240,counter)
''UART1_Write(10)
''UART1_Write(13)
Delay_ms(100)
counter=counter+20

end if

if counter >280 then
counter=40
TFT_Fill_Screen(0)
Delay_ms(100)
TFT_Write_Text("Bit Test with Interupt",5,10)
TFT_Set_Pen(CL_Green, 3)
TFT_Rectangle(1, 1, 200, 30)


end if

prova=prova+incremento

wend

end.

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”