News:

Let's find out together what makes a PIC Tick!

Main Menu

Any starter code for the PIC16F15214

Started by TimB, Jun 04, 2024, 07:56 PM

Previous topic - Next topic

TimB


I was looking for a 8pin pic for a sensor and saw the PIC16F15213/4 range. It looks ideal.

Unfortunately fuse config does not seem to have any record of the device.

So asking here in case I can shortcut some time by asking if anyone has an example fuse setup for the device and even better setting up the osc regs

Thanks

Tim


top204

#2
Here you go Tim:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' A code template for a PIC16F213 or PIC16F214 device using the internal oscillator at 32MHz.
'
' Written for the Positron8 BASIC compiler by Les Johnson.
'
    Device = 16F15214                               ' Tell the compiler what device to compile for
    Declare Xtal = 32                               ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Further declares should go here...
'

'
' Global variables, constants and aliases can go here...
'
   
'---------------------------------------------------------------------------------------------------
' The main program starts here
'
Main:   
    Setup()                                         ' Setup the program and any peripherals
   
    Do                                              ' Create a loop
   
    Loop                                            ' Do it forever
   
'---------------------------------------------------------------------------------------------------
' Setup any program variables and any peripherals before the main program starts
' Input     : None
' Output    : None
' Notes     : None
'
Proc Setup()
    Osc_Int32MHz()                                  ' Setup the device to use the internal oscillator at 32MHz

EndProc

'---------------------------------------------------------------------------------------------------
' Setup the device to use the internal oscillator at 32MHz
' Input     : None
' Output    : None
' Notes     : May not need to be called when using the 'RSTOSC_HFINTOSC_32MHZ' config1 fuse
'
Proc Osc_Int32MHz()
    OSCEN = $00          
    OSCFRQ = $05                                    ' FRQ is 32MHz 
    OSCTUNE = $00
EndProc

'---------------------------------------------------------------------------------------------------
' Setup the configuration fuses for a PIC16F15213 or PIC16F15214 device to use its internal oscillator at 32MHz
' The OSC pins are set for standard I/O pins
'
    Config1 FEXTOSC_OFF,_                           ' External Oscillator not enabled
            RSTOSC_HFINTOSC_32MHZ,_                 ' HFINTOSC is 32MHz
            CLKOUTEN_OFF,_                          ' CLKOUT function is disabled. I/O function on RA4
            VDDAR_HI                                ' Internal analog systems are calibrated for operation between VDD = 2.3V to 5.5V

    Config2 MCLRE_EXTMCLR,_                         ' MCLR pin is MCLR
            PWRTS_PWRT_OFF,_                        ' Power-up Timer is disabled
            WDTE_OFF,_                              ' WDT disabled. SEN is ignored
            BOREN_SBOREN,_                          ' Brown-out Reset enabled according to SBOREN bit
            BORV_LO,_                               ' Brown-out Reset Voltage (VBOR) set to 1.9V
            PPS1WAY_OFF,_                           ' The PPSLOCKED bit can be set and cleared as needed (unlocking sequence is required)
            STVREN_ON                               ' Stack Overflow or Underflow will cause a reset

    Config4 BBSIZE_BB512,_                          ' Boot Block Size 512 words
            BBEN_OFF,_                              ' Boot Block is disabled
            SAFEN_OFF,_                             ' SAF is disabled
            WRTAPP_OFF,_                            ' Application Block is not write protected
            WRTB_OFF,_                              ' Boot Block is not write protected
            WRTC_OFF,_                              ' Configuration Registers are not write protected
            WRTSAF_OFF,_                            ' Storage Area Flash (SAF) is not write protected
            LVP_OFF                                 ' High Voltage on MCLR/Vpp must be used for programming

    Config5 CP_OFF                                  ' User Program Flash Memory code protection is disabled

The configuration fuses can be found at the end of a device's .ppi file, and the oscillator settings are worked out by the datasheet. However, with the "RSTOSC_HFINTOSC_32MHZ" config fuse, I am not sure whether SFRs need to be adjusted, or whether the device will default to 32MHz operation at power-up. So please let us know if a call to the "Osc_Int32MHz()" procedure is required or not.

A simple loop of flashing an LED with a 500ms delay between flashes will tell you if the device is operating at the correct speed of 32MHz or not. Or a serial output with "Hello World", and if it is received correctly, the device is operating at 32MHz when the "Osc_Int32MHz()" is not called from within the Setup() procedure, but make sure the device is actually powered off then on for the testing, because the devices have a habit of holding on to what was there previously if a reset is used, and that has caught me out a few times.

JohnB

Tim Copy the 8bit_device.info in
 C:\Program Files (x86)\ProtonIDE\PDS\Includes\bin8 to
 C:\Program Files (x86)\ProtonIDE\PDS\Includes\
Fuse config will then recognise the IC16F15214.

I will be issuing a new version of Positron Studio which  resolves this and other issues.
JohnB

top204

#4
Copying it over will over-write the original "8bit_device.info" file and lose devices that the original assembler can use! They are seperate assemblers for different devices, and one assembler cannot assembler for some devices, and the other can, so altering their info files will be catastrophic for the original 8-bit devices!

The files share the same name, but they have very, very different contents, and that is why they are in a seperate folder named "bin8", so the compiler knows which assember to use for the new 8-bit devices, and the different "8bit_device.info" file is used by the assembler for a device's details!

Please, and this is very important..... Do not alter any of the compiler's files, or their placements, within the "C:\Program Files (x86)\ProtonIDE\PDS\" directory. Otherwise, the compilers will not work and they get the blame!

ALL the files in the compiler's folders are considered "sacrosanct" and should never be altered, unless it is an official installer update or a request from me, the developer and writer of the compilers.

TimB


Thanks so much for the support

Still learning every day

Tim

JohnB

How should the fuse configurator use these file then, how do I choose which file to choose, its difficult  to support Fuse Configurator if I am not given this sort of info.

PS I wont be issuing a new version of Positron Studio until this is clarified.
JohnB

top204

The compiler actually reads the .ppi file and if it has a date over a particular value, it knows to use the new assembler becaue that is one of the new devices that the original assembler no longer supports.

The format of the .info files is the same, and they do have some replication of device info in them, so the fuse configurator should read both of them for its data. It would have been better if the .ppi files were used for the config fuses, because they have all the details for a particular device, and will never change.

JohnB

I have coded for next release to Read the dev file in /Bin8/ first, if not found read the dev file in /includes/.
(I only suggested copying the Bin8 file to includes as an expedient for Tim to get FC recognising the 16F15214 device while I prepare an new update).

FC offers two options for generating code, one using compiler values the other Assembler values.  I assume Tim uses the assembler option which relies on 8bit_Dev.info file.  The compiler option uses the ppi files for fuse data.  The options were introduced because of inconsistencies between some pin/register/bit names in the compiler and assembler due mostly to Microchips inconsistent pin/register/bit naming.  Using the 8bit_Dev.info as a baseline removed the assembler errors caused by this.
JohnB