Menu

SerReceive and readAD crash pic together

Help
Chris
2012-04-24
2013-05-30
  • Chris

    Chris - 2012-04-24

    when i use readAD and SerReceive together it causes my pic to crash randomly. this code, crashes on my pic and i dont know what the problem is

    ;Chip Settings
    #chip 16F616,8
    #config MCLRE=OFF, WDT=OFF
    ;Defines (Constants)
    #define SendAHigh porta.1= on
    #define SendALow porta.1 = off
    #define RecAHigh porta.2 on
    #define RecALow porta.2 off
    ;Variables
    Dim temp As byte
    ;Interrupt Handlers
    On Interrupt ExtInt0 Call serial_receive
    InitSer 1, r4800, 1+WaitForStart, 8, 1, None, Invert
    Do Forever
        sensor(1) = readAD(an6)
        sensor(2) = readAD(an5)
    Loop
    Sub serial_receive
        SerReceive 1, temp
        SerSend 1, temp
    End Sub
    
     
  • mmotte

    mmotte - 2012-04-25

    A few things to fix.  Your "sensor" variable should be dimensioned.
    example from 'gcbasic help'   -  dim DataList(10)

    You set up an interrupt. I am not sure what is hooked to it but if the pin is  floating then power lines will trigger it at  60 hz.  Do you need the interrupt?

    Remember to keep an interrupt short.   Both of the serial routines are long.

    When you switch analog inputs , you must wait a little for the selection to stabilize. Check out section 9.2 and 9.3 in manual .

    GL

     
  • Chris

    Chris - 2012-04-25

    the external INT pin is hooked to the serial tx so receives from the pc, is low when idle, and interrupts when high, there is a pull down resistor in place to keep false interrupts. the program only crashes when readAD is in place, otherwise it runs just fine, and when i have just readAD and have the interrupt removed it also runs fine. the problem comes when i have both in place, itll crash randomly. ill have to give a small wait time in my main loop a try and see if that helps. my other option is using my other pic chip which has a hardware usart, but id like to use the 16f616 because its always soldered into place.

     
  • mmotte

    mmotte - 2012-04-27

    when i compile this and try to trace the  interrupt in the compiled.lst file, it looks like four "calls" is as deep as it goes. I am not an expert but i am thinking about the depth of the stack being only 8.  how much stack does each call use? 1 or 2 bytes?

    Usually you want the interrupt to be short in amount of work to be done. Set flags and do the work outside of the interrupt. that is what i would try next.

    You say each part works by itself which is good troubleshooting(divide and conquer).

    gl

     
  • Nobody/Anonymous

    i never really understood how the stack worked, other than each sub used stack space (but i dont know how much space each sub uses in the stack, but i do know that some functions such as the software serial routines use additional stack). i just went a different direction and changed my chip to one with a hardware uart. so far im not having the same problems. thanks for the advice

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.