DT_Analog.pbp


Closed Thread
Results 1 to 8 of 8

Thread: DT_Analog.pbp

  1. #1
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326

    Default DT_Analog.pbp

    Good day to all of you ,
    I am going to use the DT_Analog.pbp include file But I have the " ERROR: Macro DIV32?WW not found in macro file" when compiling.
    I have copied the file in the folder where the PBP executable file is stored.
    I am using pic 18 f 252 with PBP_2.50B and I am using longs.
    Thanks in advance for any help ,
    regards,
    Ambrogio

  2. #2
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    It uses DIV32, that doesn't exist when PBP LONG is used.
    You can replace this:
    R2 = DTadAccum ; put 32-bit accumulated value in PBP
    R0 = DTadAccum[1] ; registers, prepare for DIV32
    ADvalue = DIV32 DTadDivisor ; get the average value
    With something like this:
    Tmp VAR LONG
    Tmp.word0 = DTadAccum ; put 32-bit accumulated value in PBP
    Tmp.word1= DTadAccum[1] ; registers, prepare for DIV32
    ADvalue = Tmp/DTadDivisor ; get the average value

  3. #3
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    thanks for the reply,
    I have modified the include file per your direction and no more errors are displayed.
    I loaded the sample program from Darrel site.
    I am using PIC18f252, pbp 2.50, longs at 40 Mhz clock.
    I have CH-1=12 and CH-2=12 on the LCD.
    Thanks, Ambrogio

    this is the set up:

    DEFINE ADC_BIT 10
    DEFINE ADC_CLOCK 2
    DEFINE ADC_SAMPLEUS 5
    ADCON1=%10001101
    ADBITS = 12

    Main:
    FOR ADchan = 0 to 1 ; Do both AN0 and AN1
    GOSUB GetADC ; Get A/D value
    IF ADchan = 0 THEN
    LCDOUT $FE, $80 ; LCD line 1
    ELSE
    LCDOUT $FE, $C0 ; LCD line 2
    ENDIF
    LCDOUT "CH-",DEC1 ADchan," = ",DEC ADvalue," "
    NEXT ADchan
    GOTO Main:

    GOTO OverDTAnalog

    ADchan VAR BYTE ; global - A/D channel to use
    ADbits VAR BYTE ; global - # of bits in result
    ADvalue VAR WORD ; global - the final A/D value
    ADmax VAR WORD ; global - Max A/D value at this resolution
    ;--------------------
    DTadCount VAR WORD ; local - sample count
    DTadDivisor VAR WORD ; local - averaging divisor
    DTadShiftR VAR BYTE ; local - bits to shift for UnderSampling
    DTadAccum VAR WORD[2] ; local - 32-bit sample accumulator

    ;---------------------------------------------------------------------------
    GetADC:
    IF (ADbits >= 10) THEN
    DTadShiftR = 0 ; 10 11 12 13 14 15 16
    LOOKUP2 ADbits-10,[ 1, 4,16,64,256,1024,4096],DTadCount
    LOOKUP ADbits-10,[ 1, 2, 4, 8, 16, 32, 64],DTadDivisor
    ELSE
    DTadCount = 1
    DTadDivisor = 1
    DTadShiftR = 10 - ADbits
    ENDIF
    LOOKUP2 ADbits,[0,1,3,7,15,31,63,127,255,511,1023, _
    2046,4092,8184,16368,32736,65472],ADmax

    DTadAccum = 0 : DTadAccum[1] = 0 ; clear the accumulator
    DTadLoop:
    ADCIN ADchan, ADvalue ; get 10-bit sample
    DTadAccum = DTadAccum + ADvalue ; add it to the accumulator
    IF DTadAccum < ADvalue THEN ; if low word overflowed
    DTadAccum[1] = DTadAccum[1] + 1 ; increment the high word
    ENDIF
    DTadCount = DTadCount - 1 ; done with this sample
    IF DTadCount > 0 THEN DTadLoop ; loop if not done with ALL samples

    ' R2 = DTadAccum ; put 32-bit accumulated value in PBP
    ' R0 = DTadAccum[1] ; registers, prepare for DIV32
    ' ADvalue = DIV32 DTadDivisor ; get the average value
    Tmp VAR LONG
    Tmp.word0 = DTadAccum ; put 32-bit accumulated value in PBP
    Tmp.word1= DTadAccum[1] ; registers, prepare for DIV32
    ADvalue = Tmp/DTadDivisor ; get the average value
    ADvalue = ADvalue >> DTadShiftR ; Shift right if < 10-bit
    RETURN
    OverDTAnalog:
    Last edited by iw2fvo; - 20th November 2013 at 12:09.

  4. #4
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    This code should work with long and word compiler option.
    Code:
    GOTO OverDTAnalog
    
    ADchan       VAR BYTE        ; global - A/D channel to use
    ADbits       VAR BYTE        ; global - # of bits in result
    ADvalue      VAR WORD        ; global - the final A/D value
    ADmax        VAR WORD        ; global - Max A/D value at this resolution
    ;--------------------
    DTadCount    VAR WORD        ; local - sample count
    DTadDivisor  VAR WORD        ; local - averaging divisor
    DTadShiftR   VAR BYTE        ; local - bits to shift for UnderSampling
    #IF  __LONG__
        DTadAccum    VAR LONG ; local - 32-bit sample accumulator
    #ELSE
        DTadAccum    VAR WORD[2]     ; local - 32-bit sample accumulator
    #ENDIF
    ;---------------------------------------------------------------------------
    GetADC:
      IF (ADbits >= 10) THEN
        DTadShiftR = 0   ; 10 11 12 13  14   15   16
        LOOKUP2 ADbits-10,[ 1, 4,16,64,256,1024,4096],DTadCount
        LOOKUP  ADbits-10,[ 1, 2, 4, 8, 16,  32,  64],DTadDivisor
      ELSE
        DTadCount = 1
        DTadDivisor = 1
        DTadShiftR = 10 - ADbits
      ENDIF  
      LOOKUP2 ADbits,[0,1,3,7,15,31,63,127,255,511,1023, _
                      2046,4092,8184,16368,32736,65472],ADmax
      
      DTadAccum = 0 : DTadAccum[1] = 0     ; clear the accumulator
    DTadLoop:
      ADCIN  ADchan, ADvalue               ; get 10-bit sample
      DTadAccum = DTadAccum + ADvalue      ; add it to the accumulator
      #IF not __LONG__
          IF DTadAccum < ADvalue THEN           ; if low word overflowed
             DTadAccum[1] = DTadAccum[1] + 1   ;   increment the high word
          ENDIF
      #ENDIF
      DTadCount = DTadCount - 1            ; done with this sample
      IF DTadCount > 0 THEN DTadLoop       ; loop if not done with ALL samples
      #IF __LONG__
          ADvalue = DTadAccum / DTadDivisor
      #ELSE
          R2 = DTadAccum                       ; put 32-bit accumulated value in PBP
          R0 = DTadAccum[1]                    ;   registers, prepare for DIV32
          ADvalue = DIV32 DTadDivisor          ; get the average value
      #ENDIF
       ADvalue = ADvalue >> DTadShiftR      ; Shift right if < 10-bit
    RETURN
    OverDTAnalog:

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    Hi,
    Hmm, will that work on 2.50B?
    I thought the pre-processor directives like #IF / #ELSE / #ENDIF was introduced in PBP3.

    /Henrik.

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    It's time for update

  7. #7
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,154


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    Sadly, updating to v3.0 is not an option for a lot of us.

    Robert

  8. #8
    Join Date
    Jun 2008
    Location
    Varese , Italy
    Posts
    326


    Did you find this post helpful? Yes | No

    Default Re: DT_Analog.pbp

    Thanks a lot for the assistance on this matter.
    The attached files works with pbp2.50B ( I tested it with LONGS ), PIC18F252@40 MHz.
    I suggest Darrel to include it in his site. It could be useful to somebody.
    Thanks again for all.
    Ambrogio, IW2FVO

    GOTO OverDTAnalog

    ADchan VAR BYTE ; global - A/D channel to use
    ADbits VAR BYTE ; global - # of bits in result
    ADvalue VAR WORD ; global - the final A/D value
    ADmax VAR WORD ; global - Max A/D value at this resolution
    ;--------------------
    DTadCount VAR WORD ; local - sample count
    DTadDivisor VAR WORD ; local - averaging divisor
    DTadShiftR VAR BYTE ; local - bits to shift for UnderSampling
    '#IF __LONG__
    DTadAccum VAR LONG ; local - 32-bit sample accumulator
    '#ELSE
    ' DTadAccum VAR WORD[2] ; local - 32-bit sample accumulator
    '#ENDIF
    ;---------------------------------------------------------------------------
    GetADC:
    IF (ADbits >= 10) THEN
    DTadShiftR = 0 ; 10 11 12 13 14 15 16
    LOOKUP2 ADbits-10,[ 1, 4,16,64,256,1024,4096],DTadCount
    LOOKUP ADbits-10,[ 1, 2, 4, 8, 16, 32, 64],DTadDivisor
    ELSE
    DTadCount = 1
    DTadDivisor = 1
    DTadShiftR = 10 - ADbits
    ENDIF
    LOOKUP2 ADbits,[0,1,3,7,15,31,63,127,255,511,1023, _
    2046,4092,8184,16368,32736,65472],ADmax

    DTadAccum = 0 : DTadAccum[1] = 0 ; clear the accumulator
    DTadLoop:
    ADCIN ADchan, ADvalue ; get 10-bit sample
    DTadAccum = DTadAccum + ADvalue ; add it to the accumulator
    ' #IF not __LONG__
    ' IF DTadAccum < ADvalue THEN ; if low word overflowed
    ' DTadAccum[1] = DTadAccum[1] + 1 ; increment the high word
    ' ENDIF
    ' #ENDIF
    DTadCount = DTadCount - 1 ; done with this sample
    IF DTadCount > 0 THEN DTadLoop ; loop if not done with ALL samples
    '#IF __LONG__
    ADvalue = DTadAccum / DTadDivisor
    '#ELSE
    ' R2 = DTadAccum ; put 32-bit accumulated value in PBP
    ' R0 = DTadAccum[1] ; registers, prepare for DIV32
    ' ADvalue = DIV32 DTadDivisor ; get the average value
    '#ENDIF
    ADvalue = ADvalue >> DTadShiftR ; Shift right if < 10-bit
    RETURN
    OverDTAnalog:

Similar Threads

  1. Acquisition time in DT_Analog when oversampling?
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 12th April 2015, 21:52
  2. DT_Analog.pbp
    By malc-c in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 30th January 2015, 04:42
  3. DT_Analog & 12F1822 internal voltage reference
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 11th February 2014, 17:24
  4. DT_Analog Module Works Great,But Why?
    By arniepj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st October 2012, 20:32
  5. PBP File Extension: .BAS vs .PBP
    By nedtron in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th February 2006, 05:48

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts