PIC32MX170F256B interrupt problem

General discussion on mikroBasic PRO for PIC32.
Post Reply
Author
Message
relinquished
Posts: 222
Joined: 09 Apr 2011 11:08
Location: ITALY / NAPOLI

PIC32MX170F256B interrupt problem

#1 Post by relinquished » 29 Mar 2018 07:32

hi the forum, I ask for help because I'm using the pic32mx170 that the advent of 'interrupt cn register should perform a series of procedures, but they are not executed, and also the pic remains impallato in the interrupt routine, not returning to the main cycle

Code: Select all

module Rlab_Module

include Rbus_lib
include General_drive_led

'include General_drive_led
'include Rlab_Module
'dim UCSPin          as sbit at rf3_bit
'    UCSPin_dir      as sbit at trisf.3
'const Nled as word = 50

Symbol Pulsante0 = Pulsanti_Ingresso[0]
Symbol Pulsante1 = Pulsanti_Ingresso[1]
Symbol Pulsante2 = Pulsanti_Ingresso[2]
Symbol Pulsante3 = Pulsanti_Ingresso[3]
Symbol pulsante4 = Pulsanti_Ingresso[4]
Symbol Pulsante5 = Pulsanti_Ingresso[5]
symbol GPIO5     = GPIO.5
symbol GPIO4     = GPIO.4
symbol GPIO3     = GPIO.3
symbol GPIO2     = GPIO.2
symbol GPIO1     = GPIO.1
symbol GPIO0     = GPIO.0


const ID_             as byte  external
      Room            as byte  external

'dichiarazioni interfaccia 1 ingresso living
Dim GPIO              as byte

  dim UCSPin          as sbit at RB2_bit
      UCSPin_dir      as sbit at TRISB.2
      WS281xPin       as sbit at RB2_bit
      WS281xPin_dir   as sbit at TRISB.2
      RbusTx          as sbit at RB4_bit
      RbusTx_dir      as sbit at TRISB.4
      RbusRx          as sbit at RB5_bit
      RbusRx_dir      as sbit at TRISB.5
      RbusRTx         as sbit at RA4_bit
      RbusRTx_dir     as sbit at trisa.4
      led             as sbit at RA1_bit
      led_dir         as sbit at TRISA.1

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

dim Pulsanti_Ingresso as longword[6]
    ColorCheck        as longword
    
sub procedure EventUmidita(dim RW as byte)
sub procedure EventTemperature(dim RW as byte)
sub procedure EventInterface(dim RW as byte)
sub procedure EventPWM()
sub procedure EventUCS()
sub procedure EventWS()
sub procedure Interfaccia_Slave_Small_Init()
sub procedure GPort_Write()
sub function GPort_Read() as boolean


implements

const V0 as byte = 0x00

sub procedure RbusInt() iv IVT_CHANGE_NOTICE ilevel 7 ics ICS_SOFT
  CNBIF_bit = 0
  Rbus_read
  RBus_Write(buffer64)
  led = not led
end sub

Sub procedure SetCn
  anselb.b5     = 0
  DisableInterrupts()
  cnconb.ON_ = 1
  cnconb.SIDL = 0
  cnenb.cnieb5 = 1
  cnip0_bit = 1
  cnip1_bit = 1
  cnip2_bit = 1
  cnis0_bit = 1
  cnis1_bit = 1
  cnpub = 1
  cnpdb = 0
  IFS1.CNBIF = 0
  IEC1.CNBIE = 1
   EnableInterrupts()
end sub

sub procedure Interfaccia_Slave_Small_Init()
  JTAGEN_bit = 0
  Pulsanti_Ingresso[0] = 0
  Latb = 0xFFC4
  Lata.0 = 1
  TRISB.15 = 0
  TRISB.14 = 0
  TRISB.13 = 0
  TRISB.12 = 0
  TRISB.11 = 0
  TRISB.10 = 0
  TRISB.9 = 1
  TRISB.8 = 1
  TRISB.7 = 1
  TRISB.6 = 1
  TRISB.3 = 1
  TRISA.0 = 1

  anselb = 0
  ansela = 0

  led = 0
  led_dir = 0
  RBus_init
  GPIO = 0xff
  SetCn
end sub


sub procedure GPort_Write()
  RB15_bit = GPIO5
  RB14_bit = GPIO4
  RB13_bit = GPIO3
  RB12_bit = GPIO2
  RB11_bit = GPIO1
  RB10_bit = GPIO0
end sub

sub function GPort_Read() as boolean
  if (PortB.9 = V0) or (PortB.8 = V0) or (PortB.7 = V0) or (PortB.6 = V0) or (PortA.0 = V0) or (PortB.3 = V0) then
    if portb.8 = 0 then
        GPIO.5 = not GPIO.5
        RBus_Write(Rpackage(master, root, Winterface, p6, GPIO, 0x00, 0x00))
    end if
    if portb.7 = 0 then
        GPIO.4 = not GPIO.4
        RBus_Write(Rpackage(master, root, Winterface, p5, GPIO, 0x00, 0x00))
    end if
    if portb.6 = 0 then
        GPIO.3 = not GPIO.3
        RBus_Write(Rpackage(master, root, Winterface, p4, GPIO, 0x00, 0x00))
    end if
    if portb.9 = 0 then
        GPIO.2 = not GPIO.2
        RBus_Write(Rpackage(master, root, Winterface, p3, GPIO, 0x00, 0x00))
    end if
    if porta.0 = 0 then
        GPIO1 = not GPIO.1
        RBus_Write(Rpackage(master, root, Winterface, p2, GPIO, 0x00, 0x00))
    end if
    if portb.3 = 0 then
        GPIO.0 = not GPIO.0
        RBus_Write(Rpackage(master, root, Winterface, p1, GPIO, 0x00, 0x00))
    end if
    'led  = not led

    result = 1
    delay_ms(300)
    else
    result = 0
  end if

end sub

sub procedure EventUmidita(dim RW as byte)

end sub

sub procedure EventTemperature(dim RW as byte)

end sub

sub procedure EventInterface(dim RW as byte)
  select case buffer.RXTypeID
    case p1
      GPIO.0 = not GPIO.0
    case p2
      GPIO.1 = not GPIO.1
    case p3
      GPIO.2 = not GPIO.2
    case p4
      GPIO.3 = not GPIO.3
    case p5
      GPIO.4 = not GPIO.4
    case p6
      GPIO.5 = not GPIO.5
  end select
  GPort_Write()
end sub

sub procedure EventPWM()

end sub

sub procedure EventUCS()
  select case Buffer.RXTypeID
    case 1
      Pulsante0 =  RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
    case 2
      Pulsante1 =  RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
    case 3
      Pulsante2 =  RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
    case 4
      Pulsante3 =  RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
    case 5
      Pulsante4 =  RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
    case 6
      Pulsante5 =  RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
  end select
  UcsBufferWrite(Pulsanti_Ingresso)
end sub

sub procedure EventWS()

end sub


end.

Code: Select all

program ISS_test

include Rbus_lib
include Rlab_Module
include General_drive_led

' Declarations section 

const ID_    as byte   = 0x11
      Room_   as byte   = living
      Nled   as  byte  = 6
      
dim Gram     as longword[Nled]

main:
  EI()
  EnableInterrupts()
  'DisableContextSaving()
  'Main program
  WS281x_Init
  UCS_init
  Interfaccia_Slave_Small_Init()
  UcsBufferWrite(Pulsanti_Ingresso)

  
  While True
    if GPort_Read() = 1 then

     ' GPO = GPI
      GPort_Write()
      UcsBufferWrite(Pulsanti_Ingresso)
    end if
    Event
    'led = portb.3

  wend
  
end.


as you can see as long as the interrupt does not trigger the main funfiona very well, while with the advent of the interrupt the process gets stuck, and within the interrupt there are two procedures that are not executed

Code: Select all

sub procedure RBus_Write(dim arr as uint64)
  dim a as byte
  'RbusRTx = 1
  for a = 63 to 0 step - 1
    RbusTx = 1
    if arr.a = 0 then
      delay_us(10)
      else
      delay_us(20)
    end if
    RbusTx = 0
    if arr.a = 0 then
      delay_us(20)
      else
      delay_us(10)
    end if
  next a
  'RbusRTx = 0
end sub

sub procedure Rbus_Read()
  dim a,bb as byte
  for a = 63 to 0 step -1
    delay_us (11)
    if RbusRx = 1 then
      Buffer64.a = RbusRx
    end if
    delay_us(18)
    while RbusRx = 0
    wend
  next a
  DataOk = 1
end sub


relinquished
Posts: 222
Joined: 09 Apr 2011 11:08
Location: ITALY / NAPOLI

Re: PIC32MX170F256B interrupt problem

#2 Post by relinquished » 29 Mar 2018 10:51

sorry apparently I found the problem, in practice the pic is connected to a converter rs485, ie max485 and the pin rtx enables the module to write or read the data received, what happened and that I do not manage that pin when the data is sent, a voltage rise of the Rx pin is triggered, triggering an interrupt in reception, and this is why the pic.

relinquished
Posts: 222
Joined: 09 Apr 2011 11:08
Location: ITALY / NAPOLI

Re: PIC32MX170F256B interrupt problem

#3 Post by relinquished » 29 Mar 2018 10:55

now I have a new problem, since I would need to use the pin rtx of the pic (RA4_bit) as a triple-state pin, but I did not understand how to set and use the odc register (open drain configuration), you could give me a example on how to use that pin with that register

relinquished
Posts: 222
Joined: 09 Apr 2011 11:08
Location: ITALY / NAPOLI

Re: PIC32MX170F256B interrupt problem

#4 Post by relinquished » 29 Mar 2018 15:35

nothing to do, I thought I understood the problem, but I was wrong apparently the problem remains the same, that is, when the interrupt is triggered on the pin rb5, after the main loop is no longer executed and remains impaled in the routine of interrupt

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: PIC32MX170F256B interrupt problem

#5 Post by petar.suknjaja » 02 Apr 2018 09:01

Hi,
So you want to say that your MCU is stuck inside the interrupt loop?
That sounds like the counter of the interrupt routine is not set on 0 in the end, or you are clearing the wrong bit.

Can you zip the project and upload it here?



Kind regards,
Petar

relinquished
Posts: 222
Joined: 09 Apr 2011 11:08
Location: ITALY / NAPOLI

Re: PIC32MX170F256B interrupt problem

#6 Post by relinquished » 18 Aug 2018 10:29

sorry if I answer only now, but being an amateur my job takes me a lot of time, and then captain periods that I have no chance to play in my laboratory.
said this I had problems of various types that I have corrected, but the problem of the interrupt and remained in practice I go out but always falls in interrupt, and I do not know what the problem is.
I connected a two-channel oscilloscope one on the pin called pwm (rb6) and the other on the RbusRx pin (RA4) which would then be the pin where INT2 is set, and I know that on RA4 there is no change of state, but the interrupt is unleashed equally.
as you had requested I enclose the compressed project
Attachments
Relinquished_Lab_Project.rar
(107.28 KiB) Downloaded 166 times

relinquished
Posts: 222
Joined: 09 Apr 2011 11:08
Location: ITALY / NAPOLI

Re: PIC32MX170F256B interrupt problem

#7 Post by relinquished » 20 Aug 2018 10:24

fortunately I solved the problem, INTERRUPT that was perpetually in LOOP BECAUSE INSTEAD of cleaning the flag of int2, I cleaned up the flag int3 and it was this that created the continuous unleashing of the interrupt.
the rest of the errors was a chip due to the fact that I had not read the errors and some defects were in the pcb prototype, thanks to the help.

User avatar
petar.suknjaja
mikroElektronika team
Posts: 683
Joined: 05 Mar 2018 09:44
Location: Belgrade

Re: PIC32MX170F256B interrupt problem

#8 Post by petar.suknjaja » 20 Aug 2018 18:09

Hi,
Great news.
Thank you for letting us know.
Kind regards,
Petar

Post Reply

Return to “mikroBasic PRO for PIC32 General”