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.
problem with compiler Mikrobasic PIC24 during interrupt context swich
General discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Author
Message
Return to “mikroBasic PRO for dsPIC30/33 and PIC24 General”
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects