• AVR Freaks

Hot!confuse with comparator of PIC16f15313

Page: 12 > Showing page 1 of 2
Author
meeagle
New Member
  • Total Posts : 27
  • Reward points : 0
  • Joined: 2019/04/20 19:43:05
  • Location: 0
  • Status: offline
2019/10/16 19:54:01 (permalink)
0

confuse with comparator of PIC16f15313

I try to roof the current of power circuit by using the comparator to monitor the voltage of the sampling resistor, the current of power circuit is control by the PWM module, reduce the duty time the current will decline. what confuse me is that, a same section of code will work correctly at PIC16F15323, but can't work at PIC16F15313. at 16F15313, no matter what the PWM duty is, the code of reduce PWM will execute one time, and just one time(at 15323 work correctly). The code relevant paste below, any suggestion is appreciate!
 __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_OFF
 __CONFIG _CONFIG2, _MCLRE_OFF & _PWRTE_ON & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_ON & _STVREN_OFF
 __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_HFINTOSC
 __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
 __CONFIG _CONFIG5, _CP_OFF

 other code,,,,,,,,

 BANKSEL FVRCON
 MOVLW B'11000100';1.024 TO DAC
 MOVWF FVRCON
 BANKSEL DAC1CON0
 MOVLW B'10001000';FVR TO DAC1PSS
 MOVWF DAC1CON0
 MOVLW 04H;the voltage of sampling resistor is between 20mv and 120 mv
 MOVWF DAC1CON1
 BANKSEL CM1CON0
 MOVLW B'00000001';in the circuit C1IN1- link to RC1 at 15323, at 15313 is RA4
 MOVWF CM1NCH
 MOVLW B'00000101';
 MOVWF CM1PCH
 CLRF CM1CON1
 MOVLW B'10010000'
 MOVWF CM1CON0
 
LOOP1

        BANKSEL CM1CON0
        MOVLW 10H
        MOVWF 75H ;common RAM

CheckLooP

        BTFSS CMOUT,MC1OUT
        GOTO NECXC
        BTFSC CMOUT,MC1OUT ;if MC1OUT if high, confirm it again
        GOTO  DECPWM
 NECXC 

        DECFSZ 75H,F
        GOTO CheckLooP
        GOTO OVER

 DECPWM 

        BANKSEL PWM3DCH
        DECF PWM3DCH,F
        GOTO LOOP1
OVER


 other code,,,,,,,,,

 
post edited by meeagle - 2019/10/16 20:49:21
#1

22 Replies Related Threads

    ric
    Super Member
    • Total Posts : 24333
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 20:16:05 (permalink)
    +1 (1)
    I'm not wasting time trying to follow messy code that looks like this. Use some damn labels!
     
     BTFSS CMOUT,MC1OUT
     GOTO $+3
     BTFSC CMOUT,MC1OUT
     GOTO $+4
     DECFSZ 75H,F
     GOTO $-5
     GOTO $+4

     

    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!
    #2
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 20:52:03 (permalink)
    0
    ric
    I'm not wasting time trying to follow messy code that looks like this. Use some damn labels!
     
     BTFSS CMOUT,MC1OUT
     GOTO $+3
     BTFSC CMOUT,MC1OUT
     GOTO $+4
     DECFSZ 75H,F
     GOTO $-5
     GOTO $+4

     


    Sorry for the ill-formed codes, the first post have been modified. Thanks for your reply!
    #3
    1and0
    Access is Denied
    • Total Posts : 9920
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 20:52:13 (permalink)
    0
    Replace all the
            GOTO    $+-k

    with
            BRA     label

     
    Also, use variable names instead of hardcoded addresses, like 75H.
    #4
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 21:30:32 (permalink)
    0
    1and0
    Replace all the
            GOTO    $+-k

    with
            BRA     label


    Also, use variable names instead of hardcoded addresses, like 75H.

    The first post have been modified.
    I have to admit that such code is unfriendly for read and always puzzled me , grin: grinbut it's so convenient for write so I can't stop using them.
    #5
    ric
    Super Member
    • Total Posts : 24333
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 21:40:23 (permalink)
    +2 (2)
    ... and it is VERY convenient for introducing bugs, e.g. just inserting one instruction in the middle of that code will require hand adjustment of all affected offsets.
    Sorry, if you worked for me, you'd be rapidly looking for a new job if you kept doing it.

    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!
    #6
    1and0
    Access is Denied
    • Total Posts : 9920
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 21:49:05 (permalink)
    +1 (1)
    meeagle
    The first post have been modified.

    You're still using GOTO (which depends on PCLATH) instead of BRA and using hardcoded address instead of a variable name.
    #7
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 22:34:42 (permalink)
    0
    ric
    ... and it is VERY convenient for introducing bugs, e.g. just inserting one instruction in the middle of that code will require hand adjustment of all affected offsets.
    Sorry, if you worked for me, you'd be rapidly looking for a new job if you kept doing it.


    I believe I need a better method too, but I don't find that out yet.
    #8
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 22:36:52 (permalink)
    0
    1and0
    meeagle
    The first post have been modified.

    You're still using GOTO (which depends on PCLATH) instead of BRA and using hardcoded address instead of a variable name.


    I check the machine code, it's jump correctly, so I think the ill code is at other place.


    #9
    pcbbc
    Super Member
    • Total Posts : 1373
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/16 23:07:38 (permalink)
    +1 (1)
    meeagle
    I check the machine code, it's jump correctly, so I think the ill code is at other place.

    Yes, and since you only supply a snippet of your code we’ve no chance of finding it.
    #10
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 04:09:57 (permalink)
    0
    pcbbc
    meeagle
    I check the machine code, it's jump correctly, so I think the ill code is at other place.

    Yes, and since you only supply a snippet of your code we’ve no chance of finding it.

    Thanks for your reply! below is the codes(this is re-compile(have been debug, not work correctly), original codes is exceed 1500 lines so I didn't paste it all at the first post).
     
     

    #include "P16F15313.INC"    
    list p=16f15313, r=DEC   
     __CONFIG _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT1 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_OFF
     __CONFIG _CONFIG2, _MCLRE_OFF & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_OFF & _BORV_LO & _ZCD_OFF & _PPS1WAY_ON & _STVREN_OFF
     __CONFIG _CONFIG3, _WDTCPS_WDTCPS_31 & _WDTE_OFF & _WDTCWS_WDTCWS_7 & _WDTCCS_HFINTOSC
     __CONFIG _CONFIG4, _BBSIZE_BB512 & _BBEN_OFF & _SAFEN_OFF & _WRTAPP_OFF & _WRTB_OFF & _WRTC_OFF & _WRTSAF_OFF & _LVP_OFF
     __CONFIG _CONFIG5, _CP_OFF
     
     COUT1  EQU   72H
     COUT2  EQU   75H 
     PWMOUT  EQU   02H
      
     ORG 0000H
      GOTO START   
     
    START ORG 0X10
     BANKSEL ANSELA
     BCF ANSELA,PWMOUT
     BANKSEL RA2PPS
     MOVLW 0BH
     MOVWF RA2PPS
     BANKSEL PWM3CON
     CLRF PWM3DCL
     MOVLW 1DH
     MOVWF PWM3DCH
     BSF PWM3CON,PWM3EN
     BANKSEL T2CON
     MOVLW 01H
     MOVWF T2CLKCON;T2CLCK=FOSC/4
     MOVLW 20H
     MOVWF T2PR
     BSF T2CON,T2ON
     BANKSEL TRISA
     BCF TRISA,PWMOUT
     
     BANKSEL FVRCON
     MOVLW B'11000100';1.024 TO DAC
     MOVWF FVRCON
     BANKSEL DAC1CON0
     MOVLW B'10001000';FVR TO DAC1PSS
     MOVWF DAC1CON0
     MOVLW 15H;the voltage of sampling resistor is between 20mv and 120 mv
     MOVWF DAC1CON1
     BANKSEL CM1CON0
     MOVLW B'00000001';in the circuit C1IN1- link to RC1 at 15323, at 15313 is RA4
     MOVWF CM1NCH
     MOVLW B'00000101';
     MOVWF CM1PCH
     CLRF CM1CON1
     MOVLW B'10010000'
     MOVWF CM1CON0 
     
    LOOP1
            BANKSEL CM1CON0
            MOVLW 10H
            MOVWF COUT2 ;common RAM
    CHECKLOOP
            BTFSS CMOUT,MC1OUT
            GOTO NEXTC
            BTFSC CMOUT,MC1OUT ;if MC1OUT if high, confirm it again
            GOTO  DECPWM
     NEXTC
            DECFSZ COUT2,F
            GOTO CHECKLOOP
            GOTO OVER
     DECPWM
            BANKSEL PWM3DCH
            DECF PWM3DCH,F
     CALL FLASH
            GOTO LOOP1
    OVER GOTO $+0
     
    FLASH;
     BANKSEL CPUDOZE
     MOVLW B'01000111'
     MOVWF CPUDOZE
     BANKSEL TRISA
     BSF TRISA,PWMOUT;DARK
     MOVLW 64H
     MOVWF COUT1
     DECFSZ COUT1,F
     GOTO $-1
     BCF TRISA,PWMOUT;LIGHT
     MOVLW 64H
     MOVWF COUT1
     DECFSZ COUT1,F
     GOTO $-1
     BANKSEL CPUDOZE
     BCF CPUDOZE,DOZEN
     RETURN 
    END
    #11
    1and0
    Access is Denied
    • Total Posts : 9920
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 06:41:25 (permalink)
    0
    Comment off these three lines and see if it works:

            BTFSS CMOUT,MC1OUT
            GOTO NEXTC
            BTFSC CMOUT,MC1OUT ;if MC1OUT if high, confirm it again
           

    #12
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 09:24:18 (permalink)
    0
    1and0
    Comment off these three lines and see if it works:

            BTFSS CMOUT,MC1OUT
            GOTO NEXTC
            BTFSC CMOUT,MC1OUT ;if MC1OUT if high, confirm it again
           



    The "DECPWM" section work correctly, the point is CMOUT,MC1OUT is always high, no matter what the PWM ratio is,  even I set the DAC output from 1 to 31, nothing is change.
    #13
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 09:27:29 (permalink)
    0
    1and0
    Comment off these three lines and see if it works:

            BTFSS CMOUT,MC1OUT
            GOTO NEXTC
            BTFSC CMOUT,MC1OUT ;if MC1OUT if high, confirm it again
           



    I had try the CM1CON0,C1OUT_CM1CON0 bit instead of CMOUT,MC1OUT, nothing change too.


    #14
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 09:33:04 (permalink)
    0
    I have read the datasheet many times, but still can't find out what's the point I miss, so I consider if there is a relevant setting not mention at the datasheet that I did wrong coincidently.
    #15
    coffee critic
    Super Member
    • Total Posts : 378
    • Reward points : 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 10:00:52 (permalink)
    0
    Did you disconnect the programmer when running these tests?

    n_*$
    #16
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 10:15:12 (permalink)
    0
    coffee critic
    Did you disconnect the programmer when running these tests?


    Yes, I download it, and try debug mode, two method lead to the same appearance.
    #17
    1and0
    Access is Denied
    • Total Posts : 9920
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 10:17:14 (permalink)
    0
    meeagle
    The "DECPWM" section work correctly, ...

    Okay, it is just in Post #1 you said, "the code of reduce PWM will execute one time, and just one time..."
     
    Anyway, it sounds like your comparator is not setup correct.
    #18
    coffee critic
    Super Member
    • Total Posts : 378
    • Reward points : 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 10:29:07 (permalink)
    0
    I also don't see any PPS settings to tie the PWM to the pin.

    n_*$
    #19
    meeagle
    New Member
    • Total Posts : 27
    • Reward points : 0
    • Joined: 2019/04/20 19:43:05
    • Location: 0
    • Status: offline
    Re: confuse with comparator of PIC16f15313 2019/10/17 10:35:31 (permalink)
    0
    1and0
    meeagle
    The "DECPWM" section work correctly, ...

    Okay, it is just in Post #1 you said, "the code of reduce PWM will execute one time, and just one time..."
     
    Anyway, it sounds like your comparator is not setup correct.


    I am agree with you. And at other datasheet(like 16f1823), the comparator chapter mention a unknow statement after comparator initiate, so I try to wait some time, or execute the "loop1" twice, but can't see different result.
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2019 APG vNext Commercial Version 4.5