• AVR Freaks

Hot!SOMETHING STRANGE WITH PIC16F15313

Author
meeagle
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/04/20 19:43:05
  • Location: 0
  • Status: offline
2019/09/07 21:32:26 (permalink)
0

SOMETHING STRANGE WITH PIC16F15313

This PIC16F15313, when I define the RA5 as the ccp1 pwm output pin, there is nothing can be detect, when change to ra4, the pwm waveform will be output as normal, why?????
The other strange thing is, the RA0 and RA1 can't be internal pullup as normal pin, it's just always low, why????
below is the code.
#include "p16f15313.inc"
 __CONFIG _CONFIG1, _FEXTOSC_ECH & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_OFF & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_OFF
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_SC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_ON & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
 __CONFIG _CONFIG5, _CP_OFF
    
    ORG 0x0000
    GOTO START

    
START ORG 0X0008
 BANKSEL TRISA
 BCF TRISA,4
 BANKSEL RA4PPS
 MOVLW 09H
 MOVWF RA4PPS
 BANKSEL T2CON
 MOVLW 01H
 MOVWF T2CLKCON
 MOVLW 20H
 MOVWF T2PR
 BANKSEL CCPR1L
 MOVLW 10H
 MOVWF CCPR1H
 MOVLW 0C0H
 MOVWF CCPR1L
 MOVLW 9FH
 MOVWF CCP1CON
 BANKSEL T2CON
 BSF T2CON,T2ON
 BANKSEL WPUA
 BSF WPUA,1
 GOTO $+0
    END

 
#1

11 Replies Related Threads

    mbrowning
    USNA79
    • Total Posts : 1537
    • Reward points : 0
    • Joined: 2005/03/16 14:32:56
    • Location: Melbourne, FL
    • Status: offline
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/09 09:17:41 (permalink)

    Go Navy! Beat Army!
    #2
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/09 13:27:45 (permalink)
    +1 (1)
    meeagle
    This PIC16F15313, when I define the RA5 as the ccp1 pwm output pin, there is nothing can be detect, when change to ra4, the pwm waveform will be output as normal, why?????

    mbrowning has answered this in your other topic.

    The other strange thing is, the RA0 and RA1 can't be internal pullup as normal pin, it's just always low, why????

    How are you testing this?
    Those two pins are used for programming and debugging. If you are in debug mode, they are dedicated to the debugger.
    If you have the programmer connected, it will be pulling those two pins low with about 4.7k on each pin.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/11 11:19:51 (permalink)
    -1 (1)
    Thanks @ ric & mbrowning
    After test, I confirm that "_FEXTOSC_ECH " this setting make RA5 can't be use as output pin, and ra0 and ra1 is in debug mode make them always low, similarly. thanks for @ric & @mbrowning.
    and there is another bother thing, when I use the T0 and T1 to make out interrupt, when in the ISR I clear the IF bit, stop the timer and cancel the IE bit, and then the next time when I need to use the timer, either set the timer ON or set the IE bit, the IF bit will be set at once, even I cancel the GIE at fist, and clear the IF bit before setting GIE at last, the timer IF will set after a few TOSC, looks like that the timer IF bit will be fixed once it's set. I have checked all document I can find but can't find out why, ,,,,,,
    (the config words is as above)
    thanks for reading.
    #4
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/11 13:21:01 (permalink)
    +1 (1)
    The timer bits work fine as described in the datasheet, so it's more likely a bad assumption.
    Rather than describing what you think your code does, show the actual code. That avoids a lot of wasted time.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/11 20:00:20 (permalink)
    -1 (1)
    reply withdraw and changing the code.
    post edited by meeagle - 2019/09/11 20:10:15
    #6
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/11 20:23:41 (permalink)
    +1 (1)
    Why on earth are you fiddling around with the stack pointer and return address inside the interrupt service?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/14 21:27:18 (permalink)
    0
    The IF bit is working well. I simulated the 16f15313 with a kit3 and presumed the time measurement will halts as the software simulation, but it's different, so when I checking the bad code in step by step mode, there's a misconception about the IF. Thank's for reply again.
    #8
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/14 23:41:02 (permalink)
    +1 (1)
    I guess the "bad assumption" was that the IE bit clear stopped the IF bit being set.
    That is wrong, you can poll the IF bit when the IE bit is clear to see if the interrupt condition occurred.
    The ONLY thing the IE bit does is control if a jump to the service routine is triggered by the IF bit being asserted (subject to GIE and PEIE as well).
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #9
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/16 10:08:26 (permalink)
    0
    IN the step by step simulating mode, when I clrf timer's IF and have a look at the PIRs to confirm they become 0, and at the next step when I look into the timer PIRs again, they had already be set!!! This make me feel strange. now I know that, the timer at the target MCU are continue running when I halt the simulation at the MPLAB, this is not the same as software simulation.
    #10
    ric
    Super Member
    • Total Posts : 23893
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/16 13:23:04 (permalink)
    0
    Do you really mean "simulating", or "debugging" ?
    If it's "debugging", then you can optionally select if peripherals stop ("freeze"), or keep running when you are single stepping.
    From your description, I think you are debugging, and you have not selected "freeze peripherals" in the debugger setup.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #11
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: SOMETHING STRANGE WITH PIC16F15313 2019/09/16 21:18:49 (permalink)
    0
    I meant debugging, and not select the "freeze", that's what made me stuck in the IFs, thanks  a lot for the reply!
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5