Haz una pregunta
  Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos
Foros Registrarse ¿Olvidaste tu contraseña?

Temas similares

22/02/2013 #1


Problema p18f452, ENC20j60 y Mikrobasic - Cuelgo y Falla en Reset
Buenas Tardes a todos:

Me encuentro diseñando un sistema de alarmas empleando ethernet, que funcione 24/7.
El sistema esta diseñado empleando un Micro P18f452, y un modulo ethernet de la empresa geeetech.

El problema que tengo es que despues de un cierto tiempo el Modulo ethernet se apaga, incluso recibiendo informacion, y a pesar de haber implementado una rutina para reseteo en caso de no haber datos, este no se ejecuta, y el micro se cuelga, a pesar de estar activo el Watchdog.

No se si podrian darme una manito en este problema

Saludos

Adjunto el diseño y el codigo, estoy empleando el mikrobasic pro for pic y una libreria instalada para uso del enc.. la libreria Net_enc, descargada del libstock.

Código:
program remoto52nt1

include images
include http_utils
include webpage

dim
  Net_Ethernet_28j60_Rst  as sbit at RC0_bit
  Net_Ethernet_28j60_CS  as sbit at RC1_bit
  Net_Ethernet_28j60_Rst_Direction  as sbit at TRISC0_bit
  Net_Ethernet_28j60_CS_Direction  as sbit at TRISC1_bit
  
  LED_OP     as sbit at RD4_bit
        LED_TX     as sbit at RD5_bit
        LED_RX     as sbit at RD6_bit

        SPI_INT    as sbit at RC2_bit
        SPI_WOL    as sbit at RC3_bit

        OU_01      as sbit at RB0_bit
        OU_02      as sbit at RB1_bit
        OU_03      as sbit at RB2_bit
        OU_04      as sbit at RB3_bit

        IN_01      as sbit at RB4_bit
        IN_02      as sbit at RB5_bit
        IN_03      as sbit at RB6_bit
        IN_04      as sbit at RB7_bit

' Declarations section 
dim myMacAddr   as byte[6]   ' my MAC address
    myIpAddr    as byte[4]   ' my IP address
    gwIpAddr    as byte[4]   ' gateway (router) IP address
    ipMask      as byte[4]   ' network mask (for example : 255.255.255.0)
    dnsIpAddr   as byte[4]   ' DNS server IP address


dim


     datoeeprom  as byte
    dhcp_enable as byte



Const TipMod as String[7] = "CENTRAL"
     
dim counter      as integer
    counter2     as integer
    ver1         as boolean
    ver2         as boolean
    PortJob      as word
    i            as byte
    TipoAlarm    as byte
dim
    send_mark1, send_mark2, send_mark3, send_mark4, sendHTML_mark as byte
    socketImage1, socketImage2, socketImage3, socketImage4, socketHTML as ^SOCKET_28j60_Dsc
    pos as word[NUM_OF_SOCKET_28j60]




sub procedure Net_Ethernet_28j60_UserTCP(dim socket as ^SOCKET_28j60_Dsc)
end sub



sub function Net_Ethernet_28j60_UserUDP(dim udpDsc as ^UDP_28j60_Dsc) as word

 dim     value      as char[9]
         compar     as string[7]
         hx         as char
         Output     as byte
         l          as byte
         res        as byte
        tmp as string[5]
  result = 0
  LED_OP = 1
   '

  if (udpDsc^.destPort = PortJob) then
     LED_RX = 1
     asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
     for l = 0 to 7
           value[l] =  Net_Ethernet_28j60_getByte()
           if value[0] <> "_" then
              LED_OP = 0
              LED_RX = 0
              asm
                 CLRWDT         ' asm line, clear WatchDog Timer
              end asm
             ' exit
           end if
           asm
              CLRWDT         ' asm line, clear WatchDog Timer
           end asm
           if l = 7 then
              hx = value[l]
           end if
     next l
     asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
     compar = "_MCL-D-"
     res = strspn(value,compar)
     asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
     if (res = 7) then
        OutPut =  hx - 97
        Select Case Output
               Case 0
                    Counter2 = 0
                    If ver1 or ver2 then
                       TipoAlarm = 0
                       GIE_bit = 1           ' Enable global interrupt
                       TMR0IE_bit = 1          ' Enable Timer0 Interrupt
                       T0CON         = 0x86
                       TMR0H         = 0x67
                       TMR0L         = 0x67
                       counter = 0
                       OU_03 = 0
                       asm
                          CLRWDT         ' asm line, clear WatchDog Timer
                       end asm
                    end if
                    OU_01 = 1
                    OU_02 = 1 
                    ver1 = false
                    ver2 = false
                    asm
                       CLRWDT         ' asm line, clear WatchDog Timer
                    end asm
               Case 1
                    counter2 = 0
                    if not ver1 then
                       TipoAlarm = 1
                       T0CON         = 0x86
                       TMR0H         = 0x67
                       TMR0L         = 0x67
                       counter = 0
                       OU_03 = 0
                       GIE_bit = 1           ' Enable global interrupt
                       TMR0IE_bit = 1          ' Enable Timer0 Interrupt
                       asm
                          CLRWDT         ' asm line, clear WatchDog Timer
                       end asm
                    end if
                    OU_01 = 0
                    OU_02 = 1
                    ver1 = true
                    asm
                       CLRWDT         ' asm line, clear WatchDog Timer
                    end asm
                    ver2 = false
               Case 2
                    counter2 = 0
                    if not ver2 then
                       TipoAlarm = 1
                       T0CON         = 0x86
                       TMR0H         = 0x67
                       TMR0L         = 0x67
                       counter = 0
                       OU_03 = 0
                       GIE_bit = 1           ' Enable global interrupt
                       TMR0IE_bit = 1          ' Enable Timer0 Interrupt
                       asm
                          CLRWDT         ' asm line, clear WatchDog Timer
                       end asm
                    end if
                    OU_01 = 1
                    OU_02 = 0
                    ver2 = true 
                    ver1 = false
                    asm
                       CLRWDT         ' asm line, clear WatchDog Timer
                    end asm
        End Select
        goto fin
     end if
     compar = "_DPC"
     res = strspn(value,compar)
     asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
     if (res = 4) then
     end if
fin:
     'Net_Ethernet_28j60_putBytes(@value, 9)
     'Net_Ethernet_28j60_putBytes(hx, 1)
     LED_RX = 0
     'result = 29 + udpDsc^.dataLength
     asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
  end if
  result = 0
  LED_OP = 0
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
end  sub





sub procedure InitGlobals()

        for i = 0 to 5
            myMacAddr[i] = EEPROM_Read(0x20 + i)
            asm
               CLRWDT         ' asm line, clear WatchDog Timer
            end asm
        next i


        If dhcp_enable = 1 then
              ' *
              ' * if you have a DHCP server, ip address 0.0.0.0 means DCHP request,
              ' * otherwise, set your IP address here :
              ' *
              myipAddr[0]  = 0
              myipAddr[1]  = 0
              myipAddr[2]  = 0
              myipAddr[3]  = 0
              asm
           CLRWDT         ' asm line, clear WatchDog Timer
     end asm
        else
              ' *
              ' * if you don't have a DHCP server, put your network settings here
              ' *
              ' *
              for i = 0 to 3
              asm
                 CLRWDT         ' asm line, clear WatchDog Timer
              end asm
                  myIpAddr[i]  = EEPROM_Read(0x02 + i)
                  gwIpAddr[i]  = EEPROM_Read(0x07 + i)
                  dnsIpAddr[i] = EEPROM_Read(0x0C + i)
                  ipMask[i]    = EEPROM_Read(0x10 + i)
              next i
        end if
end sub

sub procedure Interrupt()

  Inc(counter2)
  TMR0IF_bit = 0          ' Set T0IE, clear T0IF
  T0CON         = 0x86
  TMR0H         = 0x67
  TMR0L         = 0x67
  asm
     CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  if Counter2 > 120 then
       
       GIE_bit = 0            ' Disable global interrupt
       TMR0IE_bit = 0          ' Disable Timer0 Interrupt
       
       delay_ms(2000)
  end if

  Select Case TipoAlarm
         Case 0
             Inc(counter)            ' Increment value of counter on every Interrupt
             OU_03 = OU_03 xor 1
             asm
                CLRWDT         ' asm line, clear WatchDog Timer
             end asm
             if (counter > 5) then
                 OU_03 = 1      ' Apaga la Alarma
                 counter = 0    ' Reset counter
                 asm
                    CLRWDT         ' asm line, clear WatchDog Timer
                 end asm
                 TipoAlarm = 2
             end if
         Case 1
             Inc(counter)            ' Increment value of counter on every Interrupt
             if (counter > 60 ) then
                  OU_03 = 1      ' Apaga la Alarma
                  counter = 0            ' Reset counter
                  asm
                     CLRWDT         ' asm line, clear WatchDog Timer
                  end asm
                   TipoAlarm = 2
              end if


  End Select
  asm
     CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  TMR0IF_bit = 0          ' Set T0IE, clear T0IF

end sub


dim j as char

main:
'   Main program 


  asm
    CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  TRISA = $00
  PORTA = $00

  TRISB = $F0
  PORTB = $0F
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  TRISD = $00
  PORTD = $00
  
  TRISE = $00
  PORTE = $00
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  Counter2 = 0
  TipoAlarm = 2
  TMR0L = 0               ' Timer0 initial value
  T0CON = 0xC7            ' Set TMR0 to 8bit mode and prescaler to 256
  GIE_bit = 1            ' Disable global interrupt
  TMR0IE_bit = 1          ' Disable Timer0 interrupt

  LED_OP = 1
  LED_TX = 1
  LED_RX = 1
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  OU_01 = 1
  OU_02 = 1
  OU_03 = 1
  OU_04 = 1
  
  ver1 = false
  ver2 = false
  
  dhcp_enable = EEPROM_Read(0x00)
   InitGlobals()
   asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
   'datoeeprom = EEPROM_Read(0x15)
  'PortJob = datoeeprom
  'datoeeprom = EEPROM_Read(0x16)
  'PortJob = PortJob   + datoeeprom*0x100
  PortJob = EEPROM_Read(0x15) + EEPROM_Read(0x16)*0x100
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
'   *
'   * starts ENC28J60 with :
'   * reset bit on PORTC.C0
'   * CS bit on PORTC.C1
'   * my MAC & IP address
'   * full duplex

  for j = 0 to (NUM_OF_SOCKET_28j60 - 1)
          pos[j] = 0
  next j
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  LED_RX = 0
  LED_TX = 0
  Net_Ethernet_28j60_stackInitTCP()
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  SPI1_Init()
   asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  Net_Ethernet_28j60_Init(@myMacAddr, @myIpAddr, Net_Ethernet_28j60_FULLDUPLEX)  ' init ethernet board
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
    if dhcp_enable = 1 then
        while(Net_Ethernet_28j60_initDHCP(5) = 0)
        asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
        LED_OP = (LED_OP) xor 1
        wend ' try to get one from DHCP until it works
        ' *
        ' * read network parameters if neccessary
        ' * by copying them into your globals,
        ' * do NOT modify the contents of the locations pointed to
        ' * by pointers which are returned by the below Spi_Ethernet_get routines
        ' *
        asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
        memcpy(@myipAddr,    Net_Ethernet_28j60_getIpAddress(),    4)  ' get assigned IP address
        asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
        memcpy(@ipMask,    Net_Ethernet_28j60_getIpMask(),       4)  ' get assigned IP mask
        asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
        memcpy(@gwIpAddr,  Net_Ethernet_28j60_getGwIpAddress(),  4)  ' get assigned gateway IP address
        asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
        memcpy(@dnsIpAddr, Net_Ethernet_28j60_getDnsIpAddress(), 4)  ' get assigned dns IP address
        asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
  else
       asm
           CLRWDT         ' asm line, clear WatchDog Timer
        end asm
        Net_Ethernet_28j60_confNetwork(@ipMask, @gwIpAddr, @dnsIpAddr)  ' use configured IP address
  end if
  


  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  Delay_ms(100)
  asm
           CLRWDT         ' asm line, clear WatchDog Timer
  end asm
  LED_OP = 0



  while(1)
    '  Process incoming Ethernet packets
    LED_TX = 1
    Net_Ethernet_28j60_doPacket()
    LED_RX = 0
    asm
           CLRWDT         ' asm line, clear WatchDog Timer
    end asm
  wend
end.
23/02/2013 #2

Avatar de Ajna

Ayudarte con algo que puede tener un millón de soluciones esta difícil, lo que si te puede decir que que, porque no ejecutas el modo de depuración, solo así puedes ver en que momento tu programa falla y resolver el problema.
Respuesta
¿Tienes una mejor respuesta a este tema? ¿Quieres hacerle una pregunta a nuestra comunidad y sus expertos? Registrate

Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2011, Crawlability, Inc.