Menu

RESOVLED: Problems with PIC16F15325 and the TEMPERATURE INDICATOR MODULE

Help
Frank
2023-04-14
2023-05-09
  • Frank

    Frank - 2023-04-14

    I need the temperature information from the TEMPERATURE INDICATOR MODULE of a PIC16F15325. Unfortunately there seems to be no routine in the GCB for this PIC.
    I managed to read out a value with this code snippet, which changes with the temperature:

    FVRCON = b'11110010'            'bit 7 FVREN: Fixed Voltage Reference is enabled
                                    'bit 6 FVRRDY: Fixed Voltage Reference output is ready for use
                                    'bit 5 TSEN: Temperature Indicator is enabled
                                    'bit 4 TSRNG: Temperature in High Range
                                    'bit 3-2 CDAFVR<1:0>: Comparator FVR Buffer is off
                                    'bit 1-0 ADFVR<1:0>: ADC FVR Buffer Gain is 2x, (2.048V)
    
    ADCON1 = b'11110011'            'bit 7 ADFM: ADC Result Format Select bit
                                    'bit 6-4 ADCS<2:0>: ADC Conversion Clock Select bits
                                    'bit 3-2 Unimplemented
                                    'bit 1-0 ADPREF<1:0>: ADC Positive Voltage Reference Configuration bits
    
    ADACT = 0x0E                    'bit 3-0 ADACT<3:0>: Auto-Conversion Trigger Selection bits => Interrupt-on change flag trigger
    
    Wait 50 us  'Time for ADC switching on 
    
    Do
    
      ADCON0 = b'11110011'            'bit 7-2 ADCON0: Temperature sensor output
                                      'bit 1 GO/DONE#: ADC Conversion Status bit => start measurement
                                      'bit 0 ADON: ADC Enable bit => activate ADC
      Do
      loop Until ADCON0.1=0 'Warten bis GO/DONE# (Bit1) Low wird => measurement ready
    
      Wait 20 ms
      SerPrint 1,TemperH
      SerPrint 1," # "
      SerPrint 1,TemperL
      SerSend 1, 13,10                        ' "Carriage Return/Line Feed"
    Loop
    

    My problem is that I do not know how to read the calibration values from the DEVICE INFORMATION AREA to convert these numerical values into temperature values.

    TABLE 6-1: DEVICE INFORMATION AREA
    ==================================
    8112h TSLR1 Unassigned (1 word)
    8113h TSLR2 Temperature indicator ADC reading at 90°C (low range setting)
    8114h TSLR3 Unassigned (1 word)
    8115h TSHR1 Unassigned (1 word)
    8116h TSHR2 Temperature indicator ADC reading at 90°C (high range setting)
    8117h TSHR3 Unassigned (1 Word)
    

    Can anyone help me with this???

    THANKS!!!

    Frank

     
  • Anobium

    Anobium - 2023-04-14

    To read the value of the memory use ProgramRead ( ProgMemAddress, DataWord )

     
  • Frank

    Frank - 2023-04-14

    Thanks! I will try it! (I did not know this command yet...)

    Frank

     
  • jackjames

    jackjames - 2023-04-14

    It would be nice to see a working example

     
    • Anobium

      Anobium - 2023-04-14

      of ProgramRead(). There are many in the demos. If using GCCode select the Demo folder using 'Open Folder' and do a search using 'in files'.

       

      Last edit: Anobium 2023-04-14
      • jackjames

        jackjames - 2023-04-14

        Thanks

         
  • Frank

    Frank - 2023-04-28

    After I read out only strange values from the DIA, I would like to ask if I am doing it right at all:

    DIM TSHR2 AS Word
    ProgramRead(0x8116,TSHR2)

    When I try to read the DeviceID at 8006h, I don't get the appropriate value back either:

    ProgramRead(0x8006,DeviceID)

    Device DEVID<13:0> Values
    PIC16F15325 11 0000 1100 0110 (30C6h)
    

    I read as DeviceID 873h from address 8006h....

    What am I doing wrong???

    THANKS!!!

    Frank

     
  • Anobium

    Anobium - 2023-04-30

    An updated system.h.

    This system.h has a new method deviceconfigurationRead()

    deviceconfigurationRead (location, store)

    Available on all Microchip PIC microcontrollers. Used for reading NON-PFM memory

    Explanation:

    deviceconfigurationRead reads information from the memory on chip that is not part of the program memory. location and store are both word variables, meaning that they can store values over 255.

    This is an advanced command which should only be used by advanced developers. Refer to the datasheet for explicit data to be read.

    ''' This demonstration is for Great Cow BASIC
    '''
    ''' This demonstration how you read the DIA section of the chip.
    '''
    '''************************************************************************
    '''
    '''  PIC: 16F18855
    '''  Compiler: GCB
    '''  IDE: GCB@SYN
    '''
    '''  Board: Xpress Evaluation Board
    '''
    '''
    '''
    '''@author  EvanV
    '''@licence GPL
    '''@version 1.00
    '''@date    30/04/2023
    '''***
    ' ----- Configuration
    'Chip Settings.
    #CHIP 16f18855,32
    
    'Generated by PIC PPS Tool for Great Cow Basic
    'PPS Tool version: 0.0.5.5
    'PinManager data: 07/03/2017
    '
    'Template comment at the start of the config file
    '
    #STARTUP InitPPS, 85
    
    Sub InitPPS
    
        'Module: EUSART
        'TX > RC0
        RC0PPS = 0x0010
        'RC0 > TX (bi-directional)
        TXPPS = 0x0010
    
    End Sub
    'Template comment at the end of the config file
    
    
    ' ----- Constants
    #DEFINE USART_BAUD_RATE 19200
    #DEFINE USART_TX_BLOCKING
    
    #DEFINE LEDD2 PORTA.0
    #DEFINE LEDD3 PORTA.1
    #DEFINE LEDD4 PORTA.2
    #DEFINE LEDD5 PORTA.3
    Dir     LEDD2 Out
    Dir     LEDD3 Out
    Dir     LEDD4 Out
    Dir     LEDD5 Out
    
    
    #DEFINE Potentiometer       PORTA.4
    Dir     Potentiometer In
    
    #DEFINE SWITCH_DOWN         0
    #DEFINE SWITCH_UP           1
    #DEFINE SWITCH              PORTA.5
    Dir SWITCH                  In
    
    ' ----- Variables
    ' No Variables specified in this example. All byte variables are defined upon use.
    
    ' ----- Quick Command Reference:
    '[todo]
    
    
    ' ----- Main body of program commences here.
    
    HSerPrintCRLF
    HSerPrint  ChipNameStr + " Great Cow BASIC Demo"
    HSerPrintCRLF
    Wait 3 s
    
    If Trim("16F18855") <> ChipNameStr Then
    
        HSerPrint "Wrong Microcontroller program intended for 16F18855"
        HSerPrintCRLF
    
    Else
    
        DIM tshr2 AS Word
        HSerPrint "0x8006: "
        deviceconfigurationRead(0x8006,tshr2)
        HSerPrint "0x"+hex(tshr2_h)
        HSerPrint hex(tshr2)
        HSerPrintCRLF
    
    End If
    
    Wait While TRUE
    

    The program above shows the DeviceID on the terminal.

    16F18855 Great Cow BASIC Demo
    0x8006: 0x306C
    
     

    Last edit: Anobium 2023-04-30
  • Anobium

    Anobium - 2023-04-30

    If you can think of a better name for the method, rather than deviceconfigurationRead () then please let me know before I write the Help!

     
  • Thomas Meier

    Thomas Meier - 2023-05-02

    Hi Anobium,
    my proposal für the method's name is: DeviceConfigRead().

    I'm new to PIC and Cow BASIC and wanted to learn how the configuration space is addressed.
    So I looked into the latest system.h and compared the functions ProgramRead() and deviceconfigurationRead() but I could not find any differences.

    I thought, that to address the config space I should activate the bit NVMREGS in NVMCON1. What did I overlook?

    Thank you in advance!

     
  • Anobium

    Anobium - 2023-05-03

    We will use DeviceConfigRead() - thank you.

    In the attached file look at line 4098. This sets NVMREGS . How? The compiler knows that certain register.bit have the different name for the same register location. So, CFGS equates to NVMREGS.

    The ASM shows the proof. Where Set CFGS ON is transformed into bsf NVMCON1,NVMREGS

    ;Set CFGS ON
        bsf NVMCON1,NVMREGS
    

    The compiler directive that supports this is #SAMEBIT (there is also #SAMEVAR). If you use GCODE IDE to search all the libraries you will find where #SameBit NVMREGS, CFGS is defined.

     
  • Frank

    Frank - 2023-05-03

    Hi Evan,
    your new "system.h" doesn't work for me. When I replace the previous one with the new one, my serial output doesn't work anymore (only garbage comes), even if I don't call ProgramRead at all...
    My current version is the 0.99.010 - is that ok?

    My read out DIA values (with old "system.h") were apparently really wrong! I had read out these values with ProgramRead: TSHR1=5822, TSHR2=5715, TSHR3=334

    WITHOUT calling ProgramRead (so just outputting the variables) I get: TSHR1=4, TSHR2=5822 TSHR3=5715
    It looks like these are just any values...

    Frank

     
    • Anobium

      Anobium - 2023-05-03

      The system.h will only work wits 1.xx.xx compiler.

      There are many dependencies across the libs.

      The old ProgramRead reads the ProgMem only.

       
      • Anobium

        Anobium - 2023-05-03

        I could add a prerequisite check to the compiler. But, this would only work on stuff going forward ( changes in the future ). So, it would be pointless.

        The general rule. Keep the toolchain and libraries at a consistent release level.

         
  • Anobium

    Anobium - 2023-05-08

    Added deviceconfigurationRead() to read Device Configuration ( additive to ProgramRead as ProgramRead limited to PFM )

    Help updated with new method.

    Now included in build 1242

     
    • Angel Mier

      Angel Mier - 2023-05-08

      Update should be live at 05:00 UTC or earlier.

       
  • Anobium

    Anobium - 2023-05-09

    THANK YOU!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.