problems on compare 2 unsigned long PIC16F

rudolf
2007-05-23
2013-03-12
  • rudolf
    rudolf
    2007-05-23

    hallo!
    You always help me a lot, maybe can help me figure out what is wrong here..

    this code seems not to work on a PIC16F628-20/IP :

       unsigned long ADC, tsetpoint, DAC;

       ADC        = 144713400;
       tsetpoint  = 148492545;
       if (ADC>tsetpoint) DAC--; else
       if (ADC<tsetpoint) DAC++;

    condition (ADC>tsetpoint) is always satisfied!

    looking on the asm code (see below),
    i could not find any error, but
        SUBWF    (_tsetpoint + 3),W
        BTFSS    STATUS,2
    according to the pic manual should check Carry flag, Zero flag change is undefined for SUBWF.

    could this be the error?

    thank you anyway for your time!
    Rudolf

    sdcc -v SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.6.4 #4665 (Mar  9 2007) (UNIX)

    part of asm file, comments are not sincronized:

    ;    .line    309; "firmware.c"    Do ADC reading and store it !!!
        BANKSEL    _ADC
        MOVF    (_ADC + 3),W
        BANKSEL    _tsetpoint
        SUBWF    (_tsetpoint + 3),W
        BTFSS    STATUS,2
        GOTO    _00200_DS_
        BANKSEL    _ADC
        MOVF    (_ADC + 2),W
        BANKSEL    _tsetpoint
        SUBWF    (_tsetpoint + 2),W
        BTFSS    STATUS,2
        GOTO    _00200_DS_
        BANKSEL    _ADC
        MOVF    (_ADC + 1),W
        BANKSEL    _tsetpoint
        SUBWF    (_tsetpoint + 1),W
        BTFSS    STATUS,2
        GOTO    _00200_DS_
        BANKSEL    _ADC
        MOVF    _ADC,W
        BANKSEL    _tsetpoint
        SUBWF    _tsetpoint,W
    _00200_DS_
        BTFSC    STATUS,0
        GOTO    _00194_DS_
    ;genSkipc:3748: created from rifx:0xbfa5217c
        MOVLW    0xff
        BANKSEL    _DAC
        ADDWF    _DAC,F
        BTFSS    STATUS,0
        DECF    (_DAC + 1),F
        GOTO    _00196_DS_
    _00194_DS_
    ;    .line    310; "firmware.c"    */
        BANKSEL    _tsetpoint
        MOVF    (_tsetpoint + 3),W
        BANKSEL    _ADC
        SUBWF    (_ADC + 3),W
        BTFSS    STATUS,2
        GOTO    _00201_DS_
        BANKSEL    _tsetpoint
        MOVF    (_tsetpoint + 2),W
        BANKSEL    _ADC
        SUBWF    (_ADC + 2),W
        BTFSS    STATUS,2
        GOTO    _00201_DS_
        BANKSEL    _tsetpoint
        MOVF    (_tsetpoint + 1),W
        BANKSEL    _ADC
        SUBWF    (_ADC + 1),W
        BTFSS    STATUS,2
        GOTO    _00201_DS_
        BANKSEL    _tsetpoint
        MOVF    _tsetpoint,W
        BANKSEL    _ADC
        SUBWF    _ADC,W
    _00201_DS_
        BTFSC    STATUS,0
        GOTO    _00196_DS_
    ;genSkipc:3748: created from rifx:0xbfa5217c
        BANKSEL    _DAC
        INCF    _DAC,F
        BTFSC    STATUS,2
        INCF    (_DAC + 1),F
    _00196_DS_

     
    • rudolf
      rudolf
      2007-05-23

      Hi, Please ignore (or delete) this post!
      actually this code is working, my bug must be is some other place.
      i apologize for that
      rudolf