Announcement

Collapse
No announcement yet.

Error: Macro DIV32?WW and Macro DIV32?cc not found in macro file?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ramius
    replied
    Thank You, Thank You, Thank you!

    Thank You, Thank You, Thank you! I can not Thank You enough! Yes it all works fine now! You are the very best!

    Sincerely, Ed

    Leave a comment:


  • Darrel Taylor
    replied
    Originally posted by Ramius View Post
    Got it I think? Is there a "preferred" place in the code so IDC will run the code and not error?
    Just add it after the include.

    Leave a comment:


  • Ramius
    replied
    Okay...

    Got it I think? Is there a "preferred" place in the code so IDC will run the code and not error?

    Code:
    '****************************************************************
    '*  Name    : Depth.bas                                         *
    '*  Author  : Ed Cannady (Original written by BrianT)           *
    '*  Notice  : Copyright (c) 2011 [select VIEW...EDITOR OPTIONS] *
    '*          : All Rights Reserved                               *
    '*  Date    : 4/4/2011                                          *
    '*  Version : 1.0                                               *
    '*  Notes   : For a 18F1320 and MS-5541                         *
    '*                                                              *
    '****************************************************************
    
    DEFINE OSC 20             'Define crystal frequency
    
    DEFINE CCP1_REG PORTB     ' Use CCP1 for 32768 master clock PORTB.3
    DEFINE CCP1_BIT 3         ' Use CCP1 for 32768 master clock PORTB.3
    
    Include "Modedefs.bas"
    include "hpwm10L.pbp"
    
    ;18F1320 EXT OSC RUNNING AT 20MHZ TO 40MHZ MCLR AS INPUT AND OSC PINS AS INPUTS
    
    #CONFIG
        __CONFIG  _CONFIG1H, _HS_OSC_1H & _FSCM_OFF_1H
        __CONFIG  _CONFIG2H, _WDT_OFF_2H & _WDTPS_8K_2H
        __CONFIG  _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_27_2L
        __CONFIG  _CONFIG3H, _MCLRE_OFF_3H
        __CONFIG  _CONFIG4L, _DEBUG_OFF_4L & _LVP_ON_4L & _STVR_ON_4L
        __CONFIG  _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
        __CONFIG  _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
        __CONFIG  _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
        __CONFIG  _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
        __CONFIG  _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
        __CONFIG  _CONFIG7H, _EBTRB_OFF_7H
    #ENDCONFIG
    
     '********************* Declaired Pins **************************
    
    FromSensor  VAR   PortA.0 'data out from the MS5541
    ToSensor    var   PortA.2 'data in to the MS5541
    Sclk        var   PortA.3 'MS5541 32.768 khz clock
    Mclk        var   PortB.3 'MS5541 Master clock for the MS5541
    Reset       VAR   PortB.0 'Detect when we have surfaced
    
    ADCON1 = 255  ' Make everything digital (no analog)
    
    TRISA.0 = 1   ' Make A.0 an input YEL
    TRISA.2 = 0   ' Make A.2 an output GREEN
    TRISA.3 = 0   ' Make A.3 an output (Sclk) BLUE
    TRISB.3 = 0   ' Make B.3 an output (CCP2) VIOLET
    
    '************** Intersema Variables *********************************   
    ' C1 to C6 are in EEROM as VAL.byte0, VAL.byte1 from 108 to 159
    C1          var   word    ' 5540 Pressure sensitivity 
    C2          var   word    ' 5540 Pressure Offset 
    C3          var   word    ' 5540 Temp Coef of pressure sensitivity
    C4          var   word    ' 5540 Temp Coef of Pressure Offset
    C5          var   word    ' 5540 Reference temperature
    C6          var   word    ' 5540 temp coef of Temp reaToSensorg
    
    D1          VAR   word    ' raw pressure word from Intersema sensor
    D2          var   word    ' raw temperature word 
    
    ' W1 to W4 are NOT stored in EEROM - they are not needed again.
    W1          var   word    'coefficient from 5540
    W2          var   word    'coefficient from 5540
    W3          var   word    'coefficient from 5540
    W4          var   word    'coefficient from 5540
    
    Chan VAR BYTE : Chan = 1
    Duty VAR WORD : Duty = 512
    Freq VAR WORD : Freq = 32768
    
    
    dT          var   long    ' intermediate calc value
    UT1         var   word    ' Calibration temperature
    II          var   byte    ' used ONLY within Intersema routines
    IJ          var   byte
    IK          var   byte
    IL          var   byte
    CalFlag     var   bit     ' calibration data read and processed
    RefPress    VAR   BIT
    temp2       var   word
    d           var   BYTE[18]
    Offset      var   long   
    Senstvty    var   long
    Pressure    var   long   
    SetPressure VAR   long
    Celsius     var   long     'a LONG allows negative temperatures 
    DegreesF    VAR   LONG     ' Our temperature in Fahrenheit
    Depth       VAR   word     ' Our depth in inches
    
    CalFlag =0                 ' We have not read the calibration data yet
    Refpress = 0               ' We have not set the reference pressure yet
    Reset = 1                  ' Start with needing to recalibrate
    
    goto endofsubroutines      ' jump subroutines at startup
    '*************************** Subroutines *****************************
    
    ResetSensor: 
    ' need 32768 @ 50% for Intersema on CCP2.
    LOW PortB.3
    @ HPWM10 _Chan, _Duty, _Freq
    Pause 10
    shiftout ToSensor, Sclk, 0, [85, 85, 0\5]  ' Sense of ToSensor is IN to 5541
    pauseus 100
    return
    
    FetchWord:
    shiftin FromSensor, Sclk, 2, [ij, ii, ik\1] 
    ' IJ is hi byte, II is lo byte, IK is a dummy and discarded  
    PAUSE 100   'Wait for data from sensor
    return
     
    CalSensor:
    if calflag = 1 then calsensordone
    ' This fetches and unpacks the factory calibration coefficients 
    ' from W1 ~ W4.  W values need not be stored.
    ' These bitmaps are unpacked into the 6 working coefficients
    ' C1 to C6 which must be stored in EEROM for later use.  
    
    ' W1
    gosub ResetSensor
    shiftout ToSensor, Sclk, 0, [87, 1\5]    ' Send W1 pattern to all sensors
    gosub fetchword                     ' get reply
    W1.byte0 = ii
    W1.byte1 = ij
    
    ' W2    
    gosub ResetSensor
    shiftout ToSensor, sclk, 0, [215, 0\5]       ' Send W2 pattern 
    gosub fetchword
    W2.byte0 = ii
    W2.byte1 = ij
    
    ' W3
    gosub ResetSensor
    shiftout ToSensor, sclk, 0, [55, 1\5]       ' Send W3 pattern
    gosub fetchword
    W3.byte0 = ii
    W3.byte1 = ij
    
    ' W4    
    gosub ResetSensor
    shiftout ToSensor, sclk, 0, [183, 0\5]       ' Send W4 pattern 
    gosub fetchword
    W4.byte0 = ii
    W4.byte1 = ij
    
    ' Unpack W1 ~ W4 into C1 ~ C6 coefficients 
    
    ' C1
    C1 = W1 >> 3
    write 108, c1.byte0
    write 109, c1.byte1
    ' C2
    C2 = ((W1 & %0000000000000111) << 10) + (W2 >> 6)
    write 110, c2.byte0
    write 111, c2.byte1
    ' C3
    C3 = W3 >> 6
    write 112, c3.byte0
    write 113, c3.byte1
    ' C4    
    C4 = W4 >> 7
    write 114, c4.byte0
    write 115, c4.byte1
    ' C5
    C5 = ((W2 & %0000000000111111) << 6) + (W3 & %0000000000111111)
    write 116, c5.byte0
    write 117, c5.byte1
    ' C6
    C6 = W4 & %0000000001111111
    write 118, c6.byte0
    write 119, c6.byte1 
          
    calflag = 1     'We are now Claibrated
    CalSensorDone:
    
    ReadSensor:
    ' D1 is Pressure - D2 is Temperature
    ' Uses LONG datatype to handle negative temperatures
    ' This routine reads the sensor and returns Pressure word 
    ' and Celsius long
    ' A, II, IJ, W and X are all destroyed
    
    gosub ResetSensor
    
    ' D1
    shiftout ToSensor, Sclk, 0, [47, 0\5]       ' Select D1 pattern
    While FromSensor = 1 
    wend        'Convert5541Delay:  
    gosub fetchword    
    
    ' This returns ii = lobyte, ij = hibyte from the sensor 
    D1.byte0 = ii
    D1.byte1 = ij
    
    ' D2    
    shiftout ToSensor, Sclk, 0, [79, 0\5]       ' Select D2 pattern 
    
    While FromSensor = 1
    wend
    
    gosub fetchword
    
    D2.byte0 = ii
    D2.byte1 = ij
    
    CalcTempPress: ' 32 bit signed arithmetic version.  Handles negatives.
    
    read 108, c1.byte0  
    read 109, c1.byte1
    read 110, c2.byte0
    read 111, c2.byte1
    read 112, c3.byte0
    read 113, c3.byte1
    read 114, c4.byte0
    read 115, c4.byte1
    read 116, c5.byte0
    read 117, c5.byte1
    read 118, c6.byte0
       
    ' formula for DS5541 are NOT the same as for DS5540
    ut1 = 8*c5 + 10000  
    dt = d2 - ut1 
    Celsius = 200 + dt*(c6 + 100)/2048 
    dEGREESf = ((18 * Celsius) + 3200)/10
    offset = c2 + ((c4 - 250)*dt)/4096 +10000
    senstvty = c1/2 + ((c3 + 200)*dt)/8192 + 3000
    pressure = (senstvty * (d1 - offset))/4096 + 1000
       
    if Refpress = 1 then CalcDepth
    SetPressure = Pressure
    RefPress = 1 
    
    CalcDepth:
    Depth = ((pressure*10) - (SetPressure*10))/2
    if Depth > 10000 then Refpress = 0 ' Our pressure reading has changed, recalculate
    if Reset = 0 then RefPress = 0     ' We have surfaced recalibrate
    
    ' NOT applying second order temperature correction in this version.  
    ' Note 2nd order correction formula ambiguity in datasheet.  
    
    if celsius < 0 then 'high bit of 32 bit number is set
    temp2 = 1000 - celsius
    else
    temp2 = 1000 + celsius
    d[17] =  temp2.byte0
    d[18] =  temp2.byte1
    endif
      
    EndOfSubRoutines:
    ' *********************** Initialise *****************************
    
    if calFlag = 0 then
    goto CalSensor
    else
    gosub ReadSensor
    endif

    Leave a comment:


  • Darrel Taylor
    replied
    I have disabled debugging of the HPWM10 file.
    And I cannot predict at which point you want to enable it.

    At any point in your program where you want debugging to start, add ...

    Code:
    ENABLE DEBUG

    Leave a comment:


  • Ramius
    replied
    Yes!

    You are correct, our posts crossed each other by only seconds! The frequency still shows high and I can probably correct this by lowering the frequency a little in the code. Any ideas why the ICD stopped working? Thanks, Ed

    Leave a comment:


  • Ramius
    replied
    Okay so the duty cycle is now correct!

    Turns out that to get a 50% duty cycle you need to set the duty cycle to 512 (1/2 of the 1023).

    Leave a comment:


  • Darrel Taylor
    replied
    Originally posted by Ramius View Post
    with a "duty cycle" of 127 declared in the variable, it is telling me the duty cycle is only 12%
    With a 10-bit dutycycle, 50% is 511. (1023 / 2)

    Leave a comment:


  • Ramius
    replied
    You are Right!

    Sorry, caught that just after I posted and corrected it. Just for reference, I am using a Saleae Logic analyser to look at everything. It tells you the frequency, duty cycle, etc. Maybe I do not know how to correctly use this analyser and with a "duty cycle" of 127 declared in the variable, it is telling me the duty cycle is only 12% and the waveform does not look like a proportional square wave (hi and low are not equal). Also just to make life more complex, the IDC goes into the wonderful "timeout"!

    Leave a comment:


  • Darrel Taylor
    replied
    The inlude file is called HPWM10L, but the command is still HPWM10.

    And you still have constants in the parameters.

    Leave a comment:


  • Ramius
    replied
    Sorry, Still Stuck!!

    I get a "Illegal opcode (_1)" with a "Found Label after column 1. (HPWM10L)"

    Code:
    DEFINE OSC 20             'Define crystal frequency
    
    DEFINE CCP1_REG PORTB     ' Use CCP1 for 32768 master clock PORTB.3
    DEFINE CCP1_BIT 3         ' Use CCP1 for 32768 master clock PORTB.3
    
    Include "Modedefs.bas"
    include "hpwm10L.pbp"
    
    ;18F1320 EXT OSC RUNNING AT 20MHZ TO 40MHZ MCLR AS INPUT AND OSC PINS AS INPUTS
    
    #CONFIG
        __CONFIG  _CONFIG1H, _HS_OSC_1H & _FSCM_OFF_1H
        __CONFIG  _CONFIG2H, _WDT_OFF_2H & _WDTPS_8K_2H
        __CONFIG  _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L & _BORV_27_2L
        __CONFIG  _CONFIG3H, _MCLRE_OFF_3H
        __CONFIG  _CONFIG4L, _DEBUG_OFF_4L & _LVP_ON_4L & _STVR_ON_4L
        __CONFIG  _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L
        __CONFIG  _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
        __CONFIG  _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L
        __CONFIG  _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H
        __CONFIG  _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L
        __CONFIG  _CONFIG7H, _EBTRB_OFF_7H
    #ENDCONFIG
    
     '********************* Declaired Pins **************************
    
    FromSensor  VAR   PortA.0 'data out from the MS5541
    ToSensor    var   PortA.2 'data in to the MS5541
    Sclk        var   PortA.3 'MS5541 32.768 khz clock
    Mclk        var   PortB.3 'MS5541 Master clock for the MS5541
    Reset       VAR   PortB.0 'Detect when we have surfaced
    
    ADCON1 = 255  ' Make everything digital (no analog)
    
    TRISA.0 = 1   ' Make A.0 an input YEL
    TRISA.2 = 0   ' Make A.2 an output GREEN
    TRISA.3 = 0   ' Make A.3 an output (Sclk) BLUE
    TRISB.3 = 0   ' Make B.3 an output (CCP2) VIOLET
    
    '************** Intersema Variables *********************************   
    ' C1 to C6 are in EEROM as VAL.byte0, VAL.byte1 from 108 to 159
    C1          var   word    ' 5540 Pressure sensitivity 
    C2          var   word    ' 5540 Pressure Offset 
    C3          var   word    ' 5540 Temp Coef of pressure sensitivity
    C4          var   word    ' 5540 Temp Coef of Pressure Offset
    C5          var   word    ' 5540 Reference temperature
    C6          var   word    ' 5540 temp coef of Temp reaToSensorg
    
    D1          VAR   word    ' raw pressure word from Intersema sensor
    D2          var   word    ' raw temperature word 
    
    ' W1 to W4 are NOT stored in EEROM - they are not needed again.
    W1          var   word    'coefficient from 5540
    W2          var   word    'coefficient from 5540
    W3          var   word    'coefficient from 5540
    W4          var   word    'coefficient from 5540
    
    
    dT          var   long    ' intermediate calc value
    UT1         var   word    ' Calibration temperature
    II            var   byte    ' used ONLY within Intersema routines
    IJ            var   byte
    IK            var   byte
    IL            var   byte
    CalFlag     var   bit     ' calibration data read and processed
    RefPress   VAR   BIT
    temp2      var   word
    d             var   BYTE[18]
    Offset      var   long   
    Senstvty  var   long
    Pressure   var   long   
    SetPressure VAR   long
    Celsius     var   long     'a LONG allows negative temperatures 
    DegreesF    VAR   LONG     ' Our temperature in Fahrenheit
    Depth       VAR   word     ' Our depth in inches
    
    CalFlag =0                 ' We have not read the calibration data yet
    Refpress = 0               ' We have not set the reference pressure yet
    Reset = 1                  ' Start with needing to recalibrate
    
    goto endofsubroutines      ' jump subroutines at startup
    '*************************** Subroutines *****************************
    
    'INCLUDE "HPWM10L.pbp"
    
    'Chan VAR BYTE
    'Duty VAR WORD
    'Freq VAR WORD : Freq = 43000
    
    'LOW PORTC.1
    'LOW PORTC.2
    
    'Main:
    '    FOR Chan = 1 to 2 
    '        FOR Duty = 0 to 1023
    '            @ HPWM10 _Chan, _Duty, _Freq
    '            PAUSE 10
    '        NEXT Duty
    '    NEXT Chan
    ' GOTO Main
    
    
    ResetSensor: 
    ' need 32768 @ 50% for Intersema
    
    LOW PortB.3
    @ HPWM10L _1, _50, _32768
    Pause 10
    
    shiftout ToSensor, Sclk, 0, [85, 85, 0\5]  ' Sense of ToSensor is IN to 5541
    pauseus 100
    return

    Leave a comment:


  • Darrel Taylor
    replied
    Hi Ed,

    You are no doubt using PBPL, which doesn't have a DIV32 command.
    Here's a modified version of HPWM10 that will work with PBPL.

    Thanks to PBPL, you are no longer limited to 32767 hz with this version.
    But resolution will decrease as the frequency increases.
    It still accepts 10-bit values, but the dutycycle steps become larger. (this is a function of the CCP module, not the code).

    Also, you cannot use constants for the Dutycycle and Frequency parameters.
    They must both be WORD variables.

    For instance ... on an 18F2520 ...
    Code:
    DEFINE OSC 10
    
    INCLUDE "HPWM10L.pbp"
    
    Chan VAR BYTE
    Duty VAR WORD
    Freq VAR WORD : Freq = 43000
    
    LOW PORTC.1
    LOW PORTC.2
    
    Main:
        FOR Chan = 1 to 2 
            FOR Duty = 0 to 1023
                @ HPWM10 _Chan, _Duty, _Freq
                PAUSE 10
            NEXT Duty
        NEXT Chan
    GOTO Main
    Attached Files

    Leave a comment:


  • Error: Macro DIV32?WW and Macro DIV32?cc not found in macro file?

    Hi All!
    I am tring to use HPWM10.PBP and I keep getting this error message!

    A snip from the code is:

    include "hpwm10.pbp"
    hpwm10 1, 50, 32768

    Thanks, Ed
Working...
X