Date and time as serial numbers (PIC with PicKit4) - Page 1
Forum section: electronics / general

author: PinheadBE
author_rank: Regular Contributor
timestamp: December 13, 2022, 12:26:46 pm
content: Hi,I usually use a TL866A programmer with the Minipro program from Autoelectric.cn to program PIC's microOne useful feature (for me) is the ability to automatically put the current system date and time as serial number during programming(See page 25 of the manual file:http://autoelectric.cn/MiniPro/T56_TL866II%20USER%20GUIDE.pdf)For some newer PIC's, I can't use MiniPro anymore, because the product is discontinued and no more updated.I wonder if it could be possible to achieve the same function using a PicKit3 or PicKit4, using MPIPE or another software (maybe with a command-line ?)Is there a pluging available to MPIPE to do that ?Thanks all for your help

author: Ian.M
author_rank: Super Contributor
timestamp: December 13, 2022, 12:51:25 pm
content: The IPE GUI programmer utility supports Microchip's SQTP serialisation, and although it doesn't natively do date/time, one of the options is to use a 'customer generated' SQTP file. See:https://microchipdeveloper.com/ipe:sqtp-startYou'll need some method of wrangling the date & time into a SQTP .num file (which is basically IntelHEX with one data record per device to be programmed, all at the *same* address), then invoking IPE with that file. You wont be able to timestamp devices individually unless you load a new SQTP file for each, so may be better off timestamping the start of a session and using an incrementing serial number within it.The IPECMD command line programmer utility is, (I believe) less versatile, and your best option there would be to script adding your serialisation data to a copy of the HEX file to be programmed using theHEXMATEutility, immediately before invoking IPECMD.

author: PinheadBE
author_rank: Regular Contributor
timestamp: December 13, 2022, 01:07:56 pm
content: Thanks Ian,I suspected something like that, but I do not have the knowledge or skills to program such a routine.I guess a simple program in Visual Basic (or else), taking the system date/time and generating the correct CRC's to create the .num file, and call both that program and the command line IPECMD form a .bat file would do the trick.Does anyone already have such a utility ?

author: Ian.M
author_rank: Super Contributor
timestamp: December 13, 2022, 02:04:03 pm
content: HEXMATE can stuff data into an IntelHEX file using its -serial (hex data), -string, or -strpack options.Generating a SQTP file containing a single record from a batch file could be as simple as:Code:SET HMPATH=%ProgramFiles(x86)%\Microchip\MPLABX\v5.25\mplab_platform\binrem Edit the above for your actual MPLAB X location"%HMPATH%\hexmate" -oSQTP.num -format=INHX8M,48 -string@1000t34="%date% %time%"rem Edit the above for the desired starting address.which outputs HEX for a string suitable for including the date & time as a PIC12/16 RETLW (opcode 0x34nn) table. You can also output 7 bit ASCII packed strings for PIC16 if you use -strpack.Note:Depending on the device core you are programming, you may need a different hex file format in the -format option.The record length (in decimal, after the comma in the -format option) *MUST* be long enough that HEXMATE doesn't split the SQTP data into multiple record lines.The same technique can directly insert the date & time into a copy of your firmware HEX file for IPECMD - remove the comma length from the -format option, (or maybe remove the whole option if HEXMATE's default is OK) and add the firmware filename before the -string option. You'll probably also want a different output filename with the .hex extension.IntelHEX addresses as used by HEXMATE are byte addresses. You need to double the instruction address for all PIC10/12/16 cores, as the hex file has two bytes per instruction word.

author: PinheadBE
author_rank: Regular Contributor
timestamp: December 13, 2022, 02:09:27 pm
content: I will definitely have a look to the Hexmate documentation.https://onlinedocs.microchip.com/pr/GUID-C3F66E96-7CDD-47A0-9AB7-9068BADB46C0-en-US-1/GUID-73F35EE0-3C8B-43E1-8C9E-61DE2C1E3D57.htmlthanks Ian for the tip

author: Ian.M
author_rank: Super Contributor
timestamp: December 13, 2022, 02:18:00 pm
content: <bump>I've added more notes above, and removed a copy/paste typo in the -string option of the HEXMATE command line.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: December 13, 2022, 03:08:19 pm
content: Another but also useful trick is that the GCC preprocessor can put the compilation date and time into the source code, by using the __DATE__ variable / directive / thingie.You can assign it to a string, and use some compiled code that can do something with it (such as output to a display, serial port or whatever).I once wrote a little function for it, which I include in all my projects, and now I can see exactly which version it is and when it was compiled whenever I encounter one of my old projects.This could also be used to generate an UUID by recompiling a small source code file and re-linking it with the rest for each time you program an uC.

author: PinheadBE
author_rank: Regular Contributor
timestamp: December 14, 2022, 01:17:28 am
content: Good to know, but I am not using GCC: I am programming my PIC's in JAL (very nice and pleasant to use language)

author: MikeK
author_rank: Super Contributor
timestamp: December 14, 2022, 11:56:25 am
content: Quote from: PinheadBE on December 14, 2022, 01:17:28 amCool...Fellow JAL user here. I have a vague memory that I made a request years ago to have compile-time access to date and time. Maybe? I dunno. You might make the request on the jallib forum and see what Rob says. It's definitely a reasonable request and wouldn't be difficult to implement.

author: PinheadBE
author_rank: Regular Contributor
timestamp: December 20, 2022, 04:12:32 pm
content: Hi Mike,The topic has already been discussed on the JAL forum, but not from the compiler point of view....It could be interesting to relaunch the subject, indeed. I'll do that.Thanks for the suggestion

author: Tnixsw
author_rank: Contributor
timestamp: December 21, 2022, 11:18:02 pm
content: MPLAB IPE - SQTP data any good?You would have to type it in manually and set in memory where you want it placed.cheersTony