SinelaboreRT Header Logo

SinelaboreRT

As simple as possible, but not any simpler!

User Tools

Site Tools


wiki:examples:pic_tutorial

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:examples:pic_tutorial [2019/05/01 20:50] pmuellerwiki:examples:pic_tutorial [2022/08/17 19:43] (current) – Discussion status changed pmueller
Line 1: Line 1:
 ====== Getting started with the PIC16F18446 and State Machines ====== ====== Getting started with the PIC16F18446 and State Machines ======
-This tutorial explains to use of state machines with the PIC16F18446 Curiosity Nano board. It provides 2k of RAM and 16k program memory. More than enought for this small tutorial.+This tutorial explains the use of state machines with the [[https://www.microchip.com/DevelopmentTools/ProductDetails/DM164144|PIC16F18446 Curiosity Nano]] board. It provides 2k of RAM and 16k program memory. More than enought for this small tutorial.
  
-Pre-requisites if you want to follow all steps yourself: +{{ :wiki:news:pic16f18446.png |}} 
-Java installation +(Source: Microchip) 
-- MPLab X IDE + 
-- SinelaboreRT demo +Install the required software if you want to follow all steps yourself. Otherwise just go on reading. 
-Graphviz (for editing the state machine)+  * [[https://www.oracle.com/technetwork/java/javase/downloads/index.html|Java installation]] 
 +  * [[https://www.microchip.com/mplab/mplab-x-ide|MPLab X IDE]] 
 +  * [[wiki:download|Sinelabore demo]] 
 +  * [[https://graphviz.gitlab.io/download/|Graphviz (for editing the state machine)]]
  
 For this tutorial we will use just the push botton and the LED on the board. So you can follow it without any additional hardware required. The LED shall blink all the time. The frequency can be changed from slow to fast by pressing the button. Simple enough but sufficient to show all the key concepts we are going to use. For this tutorial we will use just the push botton and the LED on the board. So you can follow it without any additional hardware required. The LED shall blink all the time. The frequency can be changed from slow to fast by pressing the button. Simple enough but sufficient to show all the key concepts we are going to use.
  
-The PINs are allocated as shown in the next figure using the MPLAP X IDE pin manager. The 4MHz system clock and the 10ms Timer0 timer tick were also configured with the Resource Manager. I've not used this configurator before. But have to say that it is a very convinient way to setup the hardware. I would wish to have the same for the MSP430 μCs I also often use.+The PINs are allocated using the MPLAP X IDE Resource Manager as well as the 4MHz system clock and the 10ms Timer0. I've not used this configurator before. But have to say that it is a very convinient way to setup the hardware. I would wish to have the same for the MSP430 μCs I also often use.
  
-===== Step 1 - Deciding the system archtecture =====+===== Step 1 - Deciding the system architecture =====
 For small systems e.g. sensor nodes it is usually sufficient use a main loop design. The main loop cycles endlessly and waits for events. Events are benefitially stored in an event queue. The queue is filled from timer events, other state machines (cooperating machines) or interrupt handlers. If events are available the state machine(s) are called from the main loop to process them. For small systems e.g. sensor nodes it is usually sufficient use a main loop design. The main loop cycles endlessly and waits for events. Events are benefitially stored in an event queue. The queue is filled from timer events, other state machines (cooperating machines) or interrupt handlers. If events are available the state machine(s) are called from the main loop to process them.
  
-In our little example events are sent from the keyboad interrupt and from a software timer module which is called regulary from the cyclic hardware timer. The following figure shows the system archtecture.+In our little example events are sent from the keyboad interrupt and from a software timer module which is called regulary from the cyclic hardware timer. The following figure shows the system architecture.
  
 {{ :wiki:mainloop_ext.png?400|}} {{ :wiki:mainloop_ext.png?400|}}
Line 51: Line 54:
 </code> </code>
  
 +In the library folder (see project tree below) the required timer and fifo files are provided. They can easily reused also with other Controller types. I used them in several MSP430 projects before.
  
 ===== Step 2 - Realizing the state machine ===== ===== Step 2 - Realizing the state machine =====
Line 72: Line 75:
  
 ===== Step 3 - Integrating the state machine in MPLAB X ===== ===== Step 3 - Integrating the state machine in MPLAB X =====
-The generated state machine code can be easily added to the PIC project. It is recommended to create a new folder e.g. called ''state_machine_generated_files''. To convienently edit +The generated state machine code files can be easily added to the PIC project. It is recommended to create a new folder e.g. called ''state_machine_generated_files'' All state machine related files go in there. ''sm.scc'' contains the state machine model. ''sm.c/h'' contains the generated state machine code. 
-the state machine model and generate code from it two batch files were created. Call ''edit.bat'' to start up the editor. And call ''gen.bat'' to generate the code. See the output when calling gen below.+ 
 +The following figure shows the project tree with all generated files. 
 +{{:wiki:examples:pic_example_tree.png?400|}} 
 + 
 +To convienently edit the state machine model and generate code from it two batch files were created.  
 +Call ''edit.bat'' to start up the editor. And call ''gen.bat'' to generate the code. The generated files start all with the prefix ''sm_'' (see command line). The output when calling ''gen.bat'' is shown below. 
  
 <code> <code>
Line 89: Line 97:
 </code> </code>
  
-The code generator also needs a configuration file to set basic parameters. Take a look into the configuration +The code generator needs a configuration file to set basic parameters. Take a look into the configuration 
-file and read the manual if the meaning of the parameters is not clear.+file and read the {{:wiki:downloads:sinelaborert.pdf|Manual}} if the meaning of the parameters is not clear.
  
 ===== Wrapup ===== ===== Wrapup =====
Line 98: Line 106:
 machines and by using more than one software timer. machines and by using more than one software timer.
  
-Use the example and expand it to learn.+Use the example and expand it to learn. To receive a copy just send a mail.
  
 Hope you like the tutorial Hope you like the tutorial
Line 106: Line 114:
 Peter Peter
  
-{(rater>id=01052019|name=How do you like this article?|type=rate)} + 
-~~DISCUSSION|Leave your comments~~+~~DISCUSSION:closed|Leave your comments~~
    
 {{tag>[PIC Application_Example]}} {{tag>[PIC Application_Example]}}
 +
  
  
wiki/examples/pic_tutorial.1556736602.txt.gz · Last modified: 2019/05/01 20:50 by pmueller

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki