Hot!MPLAB X and Python

Author
rgilliom
Senior Member
  • Total Posts : 77
  • Reward points : 0
  • Joined: 2006/12/29 11:13:29
  • Location: 0
  • Status: offline
2013/05/04 07:09:33 (permalink)
5 (2)

MPLAB X and Python

I am certainly not a power user, but I discovered a nice feature which may be helpful to others.  I have a client who needs to be able to recompile my project with changing parameters.  The relationship between these parameters is complex enough that it is very difficult -- maybe even impossible -- to handle with C macros.  Some may eventually need to be calculated iteratively.  The simple answer is to give the customer a single text file in the project with embedded instructions on how to set the parameters.  
 
Then in the build options of the project configuration I select "execute this line before the build".  In that line I simply call a Python script to parse the data setup file and rewrite a C header file on the fly.  I can do limit checking and data value integrity before the compiler gets anything.  In this way I can keep the instructions to the client simple and intuitive and Python takes care of the heavy lifting behind the scenes.
 
I have also used this technique to automatically generate thousands of lines of assembly language code on the fly for use in the dsPIC EP series.  These chips are very fast, but have a substantial penalty for branching.  Python allows me to take a simple script and generate long straight-line assembly language code for very time-critical DSP processes.
 
I was a skeptical adopter of MPLABX but this feature alone has made my life much easier.  
 
Hope it helps someone else.
 
~r
 
#1

9 Replies Related Threads

    RISC
    Super Member
    • Total Posts : 5272
    • Reward points : 0
    • Status: offline
    Re:MPLAB X and Python 2013/05/04 08:36:22 (permalink)
    +1 (1)
    Hi,
     
    Very interesting information.
    Even better would be if you could post an exemple project showing how you improve dsPIC33 performance.
     
    Regards
    #2
    rgilliom
    Senior Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2006/12/29 11:13:29
    • Location: 0
    • Status: offline
    Re:MPLAB X and Python 2013/05/04 09:19:38 (permalink)
    +1 (1)
    Give me a couple days.  I'll post an example of a Python assembly language code generator.
     
    ~r
     
    #3
    rgilliom
    Senior Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2006/12/29 11:13:29
    • Location: 0
    • Status: offline
    Re:MPLAB X and Python 2013/05/04 13:38:47 (permalink)
    0
    Here is a rather crude example; however, it does illustrate how to generate a rather extensive source code file from a high level script.  The idea is that the dsPIC512EP series processors have a huge FLASH space which can be exploited to flatten loops in code.  The EP core eats up about 5 clock cycles for a decision branch and this is expensive in systems which are sampling and processing data at 1 MHz sampling rates.
     
    https://dl.dropboxusercon...u/40558372/adc_asm.zip
     
    To use this run the file process.py with a Python 3.x.  NOTE: It will not run with Python 2.7.  I apologize in advance for how undocumented things are; however, I wrote this in an afternoon when I was trying to generate about 4000+ lines of debugable code.  It worked well for me, and I never expected anyone else to see it.
     
    The fle anaio.py illustrates a Pythonic way of defining functions on the fly from a simple table of values.  This is a rather nice way to get pin_io functions defines.
     
    I also use Python to write C source code files for configuring a large number of I/O pins on some of the larger processors.  I have used it for menu generation in C in the PIC18 family.  I find that it is a good complement to the embedded world.  I'm glad I took the time to learn it.
     
    post edited by rgilliom - 2013/05/04 18:43:07

    Attachment(s)

    Attachments are not available: Download requirements not met
    #4
    rgilliom
    Senior Member
    • Total Posts : 77
    • Reward points : 0
    • Joined: 2006/12/29 11:13:29
    • Location: 0
    • Status: offline
    Re:MPLAB X and Python 2013/05/04 13:46:44 (permalink)
    0
    By the way, if you want to run this, but are afraid of downloading Python 3.3, you can download Pyzo from www.pyzo.org.  This is a scientific Python IDE environment with its own Python 3.3 engine embedded within it.  It won't corrupt your Python 2.x system.  Although you can download Python 3.3 and it comes with a launcher which makes it easy for Python 2.7 and Python 3.3 to coexist on the same machine.  I avoided the Python 3.x migration for a long time, but I think it is finally time to make the jump.
     
     
    #5
    Mamta_Parida
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/01/22 04:52:24
    • Location: 0
    • Status: offline
    Re:MPLAB X and Python 2018/03/13 02:05:15 (permalink)
    0
    hello rgilliom,
     
    I'm new to Python. Actually i just want to know how you are calling a script file inside MPLAB file. If you have any complete project than request you to share so that it will be helpful for us. 
    #6
    Aussie Susan
    Super Member
    • Total Posts : 3331
    • Reward points : 0
    • Joined: 2008/08/18 22:20:40
    • Location: Melbourne, Australia
    • Status: offline
    Re:MPLAB X and Python 2018/03/13 18:13:37 (permalink)
    +1 (1)
    Mamta - do you realise that this thread is 5 years old?
    Don't expect too much as a response.
    Susan
    #7
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re:MPLAB X and Python 2018/03/13 18:47:50 (permalink)
    0
    Mamta_Parida
    ...
    I'm new to Python. Actually i just want to know how you are calling a script file inside MPLAB file.

    Wasn't this explained in the very first post?
    rgilliom
    ...
    Then in the build options of the project configuration I select "execute this line before the build".  In that line I simply call a Python script to parse the data setup file and rewrite a C header file on the fly.  I can do limit checking and data value integrity before the compiler gets anything.  In this way I can keep the instructions to the client simple and intuitive and Python takes care of the heavy lifting behind the scenes.


    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #8
    Mamta_Parida
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2018/01/22 04:52:24
    • Location: 0
    • Status: offline
    Re:MPLAB X and Python 2018/03/13 20:38:15 (permalink)
    0
    If any project is available than its gud to clear my doubt...If you have any idea than plz share any project that how to call a script file in MPLAB. I tried to calling that but not getting a proper result.
    #9
    qɥb
    Monolothic Member
    • Total Posts : 3329
    • Reward points : 0
    • Joined: 2017/09/09 05:07:30
    • Location: Jupiter
    • Status: offline
    Re:MPLAB X and Python 2018/03/13 20:43:02 (permalink)
    0
    Very difficult to help if you don't say what exactly you tried, and what result you DID get...
     

    This forum is mis-configured so it only works correctly if you access it via https protocol.
    The Microchip website links to it using http protocol. Will they ever catch on?
    PicForum "it just works"
    #10
    Jump to:
    © 2018 APG vNext Commercial Version 4.5