Announcement

Collapse
No announcement yet.

NAP restarts code on 16F18323

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NAP restarts code on 16F18323

    Hi, I'm trying to move a project from a 16F688 to a 16F18323 and I'm having trouble with the SLEEP and NAP functions.
    I'm trying to run the following test code but after a NAP or SLEEP the code restarts from the beginning on the 16F18323 rather than continuing on from the next line (which it does on the 16F688). This causes the LED to flash very fast.
    It works fine with a PAUSE rather than a NAP. Can anyone point me in the right direction?

    Code:
    ' Compiler : PICBASIC PRO Compiler 3.1.3.4
    ' Assembler : PM or MPASM
    ' Target PIC : 16F18323
    ' Hardware : Non specific
    ' Oscillator : internal
    
    
    ' ******* Setup Pic *******
    
    #CONFIG
    
    __config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
    __config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _WDTE_ON & _LPBOREN_OFF & _BOREN_ON & _BORV_HIGH & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
    __config _CONFIG3, _WRT_OFF & _LVP_OFF
    __config _CONFIG4, _CP_OFF & _CPD_OFF
    
    
    #ENDCONFIG
    
    
    TRISA = %00010111 ' set RA5 as out put and the rest of PORTA is input.
    
    TRISC = %00001110 ' RC0, RC4 and RC5 output, the
    ' rest of PORTC is input
    
    WPUA = %00000011 ' Enable Pull ups on port A
    WPUC = %00000000 ' Enable Pull ups on port C
    
    
    ' ******* Setup PBP *******
    
    DEFINE OSC 32 ' Tell PBP that Pic is running at 32Mhz
    
    
    ' ******* Create pin Aliases *******
    
    
    RED_LED VAR PORTC.0 ' Assign name "RED_LED" to PORTC.0
    
    mainloop:
    
    high RED_LED 'Turn on LED
    nap 4 ' Sleep for 288ms
    low RED_LED ' Turn off LED
    nap 4 ' Sleep for 288ms
    high RED_LED 'Turn on LED
    nap 4 ' Sleep for 288ms
    low RED_LED ' Turn off LED
    nap 7 ' Sleep for 2.308s
    nap 5 ' sleep for 0.576s
    nap 4 ' sleep for 0.288s
    
    goto mainloop
    
    
    End



  • #2
    I had a bit more of a play checking some other io and I was getting some really erratic control. So something isn't right.
    I'm using Pic Basic Pro 3.1.3.4, MPLAB X IPE v5.50 and a PicKit 3.

    Comment


    • #3
      I'll test it when I get a chance. It will probably be over the weekend.
      Charles Leo
      ME Labs, Inc.
      http://melabs.com

      Comment


      • #4
        Thanks so much for looking into this for me Charles.
        If i change the NAP to a PAUSE it the LED flash works fine.
        I tried checking my other outputs, I made PORTA.5 (motor forward) turn on and off at the same time as the LED with the following result.
        The LED would no longer turn on at all, the motor would sometimes work with the correct timing, other times just continuously run and sometimes work with incorrect timing.

        Code:
        ' ******* Create pin Aliases *******
        
        
        RED_LED VAR PORTC.0 ' Assign name "RED_LED" to PORTC.0
        M_F VAR PORTA.5   ' Motor Forwards
        M_R VAR PORTC.4   ' Motor Reverse
        
        mainloop:
        
        high RED_LED
        high M_R 
        pause 500
        
        low RED_LED
        low M_R
        pause 500
        
        high RED_LED
        high M_R
        pause 500
        
        low RED_LED
        low M_R
        pause 2000
        
        goto mainloop

        Comment


        • #5
          The commands work fine for me, but I think you're reading the wrong column on the NAP command page in the reference manual. Judging by the comments in the code, you're giving it numbers for the 16F and not the 16F1.

          I'm not having any problems with SLEEP.
          Charles Leo
          ME Labs, Inc.
          http://melabs.com

          Comment


          • #6
            Thanks Charles, yes I still had NAP set for the 16F rather than the 16F1. I didn't realise this changed with the different PIC, I thought it was restarting rather than just flashing really quickly.
            I also figured out that the erratic control is when the Pickit 3 is connected, if i disconnect it after programming everything runs fine. (The 16F688 didn't have this issue). I checked the voltage on all the pins that the Pickit 3 connects to and the only difference is that the ICSPDAT and ICSPCLK are held at 0V when it's connected and appear to be floating at 1.3 V when it's disconnected. This is with a 3V VDD (externally powered).

            Comment

            Working...
            X