Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Strange I/O hearbeat every 2 seconds with PIC16LF15313 ...<SOLVED>

Status
Not open for further replies.

Beau Schwabe

Active Member
Here is a strange one I can't quite seem to pinpoint. At first I thought it was the Watchdog timer, and then possibly an Interrupt, but neither one of those seem to be causing a 2ms pulse every 2 seconds.
I have reduced the code down to a bare minimum and still see the issue (See scope images)

Also moved the power supply to battery power and it is still present.

Any thoughts would be welcome

Code:
#include "p16lf15313.inc"
    
CONFIG1 = _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
CONFIG2 = _MCLRE_OFF & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_ON & _STVREN_ON
CONFIG3 = _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
CONFIG4 = _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_ON
CONFIG5 = _CP_OFF
    
    org        0
    goto    Init
    
    org        100
Init:   
    
    banksel LATA
    movlw   b'00000000'
    movwf   LATA
    
    banksel TRISA
    movlw   b'00000000'
    movwf   TRISA
    
    banksel LATA
    bsf    LATA,2

Main:
    goto Main
    
    end
 

Attachments

  • Scope_A.png
    Scope_A.png
    411.2 KB · Views: 235
  • Scope_B.png
    Scope_B.png
    438 KB · Views: 253
Nothing else connected ... I program with a PICkit 3 ... but I removed it from that. It's just on a Solder less bread board right now. I was doing some proof of concepts for a project and noticed the behavior.
 
Have you tried a different chip?

Mike.
BTW, what is LPBOR - Low Power Brown Out Reset?
 
Mike,

I just programmed a second micro and it's the same thing. All I have is power and ground connected... scope is on pin 5 with a shared ground. Scope is galvanically isolated.

Yes - "LPBOR - Low Power Brown Out Reset "
 
Got me stumped. Have you checked for an errata sheet?

Mike.
As for LPBOR, I was asking how it differed from normal BOR? They appear to be the same.
 
Yeah, I've been programming for years, and this is a first, however this particular PIC micro is new to me. On any othe micro, the code just works.
 
Have you checked that it definitely isn't being reset. I think I have some of these at home (in school atm) so may be able to play with this later.

Mike.
 
Something wrong here. The LF series is supposed to run 2.0 to 3.6V according to the datasheet, but your scope captures show 5V P-P.
So is it just the "F" series, or the LF" as your title states?
Other suggestion, if nothing connected, and different chips show the same, then is it the power supply? Try another...
 
I second the suggestion of the power supply. Or, better yet, check if you have a short circuit. We Lost a little clipping of a resistor into a breadboard and caused a short. Most newer smps will "hiccup" to stay below current limit when they are connected to a short. They cycle at about 1 or 2 seconds until they hit current maximum and then cut out again. They, in 1 or 2 seconds, they try again.
 
Sagor1,

Dang, I thought you might have been onto something I missed. I lowered the voltage to 3V and then to 2V on a 3rd micro (to make sure I didn't damage it in the first two attempts) and still observe the same behavior.

EDIT
Mike, it does actually go into reset (See attached image Channel 2 shows the reset)... Mike, I'm certain it isn't going into reset ... I modified the code just before "Main:" slightly, so that an io pulses HIGH then LOW at the beginning

So why does this code go into reset? Three different micros, and I changed the position on the SBB. There are no shorts, and there is a 10uF cap across pins 1 and 8

Code:
;WAS
    banksel LATA
    bsf    LATA,2

    Main:

;IS
    banksel LATA
    bsf    LATA,2

    bsf    LATA,1
    nop
    nop
    nop
    nop
    bcf    LATA,1

    Main:
 

Attachments

  • Scope_C.png
    Scope_C.png
    631.5 KB · Views: 249
Last edited:
What happens if you add a watchdog reset in the main loop ??

It could be some kind of device but that means the watchdoc is not disabled when it should be..
 
SOLVED!

The problem is in the WDT (Watch Dog Timer)

Upon a reset the micro goes into a low speed mode and enables the WDT regardless of what you set the configuration bits to.
The low speed mode is relatively easy to programmatically correct...
Code:
    banksel OSCCON1
    movlw   b'00010000'
    ;         X....... Reserved
    ;         .XXX.... OSC Source
    ;         ....XXXX Divider
    movwf   OSCCON1
   
    banksel OSCFRQ
    movlw   b'00000110'
    ;         XXXXX... Reserved
    ;         .....XXX HFINTOSC Frequency Selection
    movwf   OSCFRQ

Even if you enable the SWDTEN (Software Watch Dog Timer Enable) from the configuration bits, it still seems to have no control
programmatically from the WDTCON0 register to disable it.
Code:
    banksel WDTCON0
    movlw   b'00000000'
    ;         XX...... Unemplemented
    ;         ..XXXXX. WDT Prescale
    ;         .......X WDT Software Enable
    movwf   WDTCON0

The "SOLUTION" I found was to set the WDT clock source to any of the 'RESERVED' sources so it simply doesn't increment.
I don't like pointing to a reserved location, but I can't find any way to programmatically dissable the WDT after a reset without having to feed the WDT with a CLRWDT

Code:
    banksel WDTCON1
    movlw   b'01110000'
    ;         X....... Unemplemented
    ;         .XXX.... WDT Clock Select
    ;         ....X... Unemplemented  
    ;         .....XXX WDT Window Select
    movwf   WDTCON1

############################################################################
Complete TEST CODE below
############################################################################
Code:
#include "p16lf15313.inc"
    
CONFIG1 = _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_ON & _FCMEN_ON
CONFIG2 = _MCLRE_OFF & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_ON & _STVREN_ON
CONFIG3 = _WDTCPS_WDTCPS_31 & _WDTE_SWDTEN & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
CONFIG4 = _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_ON
CONFIG5 = _CP_OFF
    
    RES_VECT  CODE    0x0000            ; processor reset vector
    goto    Init            ; go to beginning of program
    
    MAIN_PROG CODE                      ; let linker place main program
Init:   
    
    banksel LATA
    movlw   b'00000000'
    movwf   LATA
    
    banksel TRISA
    movlw   b'00000000'
    movwf   TRISA
    
    banksel LATA
    bsf    LATA,2

    bsf    LATA,1
    nop
    nop
    nop
    nop
    bcf    LATA,1
    
    banksel OSCCON1
    movlw   b'00010000'
    ;         X....... Reserved
    ;          .XXX.... OSC Source
    ;         ....XXXX Divider
    movwf   OSCCON1
    
    banksel OSCFRQ
    movlw   b'00000110'
    ;         XXXXX... Reserved
    ;         .....XXX HFINTOSC Frequency Selection
    movwf   OSCFRQ
 
    banksel WDTCON0
    movlw   b'00000000'
    ;         XX...... Unemplemented
    ;         ..XXXXX. WDT Prescale
    ;         .......X WDT Software Enable
    movwf   WDTCON0
    
    banksel WDTCON1
    movlw   b'01110000'
    ;         X....... Unemplemented
    ;         .XXX.... WDT Clock Select
    ;         ....X... Unemplemented   
    ;         .....XXX WDT Window Select
    movwf   WDTCON1

    
    
    banksel LATA
Main:
    ;bsf    LATA,2
    ;clrwdt
    ;bcf    LATA,2
    goto Main
    
    end
 

Attachments

  • Screenshot-1.png
    Screenshot-1.png
    42.6 KB · Views: 234
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top