4

I heard it is possible to write an Operating System, using the built in bootloader and a kernel that you write, for the PIC microcontroller. I also heard it has to be a RTOS.

  1. Is this true? Can you actually make an operating system kernel (using C/C++) for PIC?
  2. If yes to 1, are there any examples of this?
  3. If yes to 1, would you need any type of software to create the kernel?
  4. Is Microchip the only company that makes PIC microcontrollers?
  5. Can the PIC microcontroller be programmed on a mac?

Thanks!

Coder404
  • 742
  • 2
  • 7
  • 21
  • 1
    Why do you think you need an operating system on a small micro-controller such as a PIC ? – Paul R May 01 '12 at 21:03
  • @PaulR Its a project in which I'm writing a small os that can do many things for a small device. PIC is small, supported, modern and inexpensive. – Coder404 May 01 '12 at 21:08
  • @PaulR - As a professional embedded programmer, I find that using an RTOS on a PIC is almost always a better idea than not. – Adam Casey May 02 '12 at 12:24
  • @Adam: interesting - I would have thought that a full RTOS would be overkill for most PIC applications, but I can see the value of a small multitasking kernel. – Paul R May 02 '12 at 12:26
  • 1
    @PaulR - Agreed; there are different levels of RTOS... FreeRTOS is a small multitasking kernel, and exactly the right fit on a PIC. We have found that it's almost always better than writing one's own scheduler, especially on the PIC24 and up. – Adam Casey May 02 '12 at 12:32
  • There is a microcontroller based computer called the Maximite which uses the PIC32. It ships with an embedded BASIC interpreter called [MMBasic](http://www.mmbasic.com) – Chris Tusa Apr 25 '13 at 19:21

5 Answers5

7
  1. Yes, you can write your own kernel (I have written 2 of my own). Yes you can write it in C for PIC. If you want pre-emptive scheduling, then you're going to have a real tough time avoiding assembly completely when writing the context switch. On the other hand, you can easily write a cooperative kernel purely in C (I have done this myself). (Note that creating an operating system is not a simple task... I'd get your feet wet in pure C first, then USE an OS or two, then try creating one.)

  2. An excellent example of this is FreeRTOS. It has preexisting ports (i.e. MPLAB projects that run without any modification on the Explorer16 demo board) for PIC24F, PIC33F, and PIC32MX (as well as 20-some odd other official ports for other vendors' devices). PIC18F is supported but it's not pretty...

  3. You only need MPLAB to create the kernel (free from Microchip). It can work interchangably with C and assembly. Depending on the processor, there are free versions of their C30 and C32 compilers to go with MPLAB.

  4. PIC is a type of microcontroller, and is a trademark of Microchip. Many other companies make microcontrollers and call them something else (e.g. AVR, LPC, STM32).

  5. Yes, the new version of MPLAB X is supported on Mac, Linux and Windows.

Nathan Wiebe
  • 794
  • 5
  • 12
  • +1 for fully answering my question! Thank you! – Coder404 May 02 '12 at 21:44
  • An aditional note is that you can use other IDE's to program for PIC microcontrolers like ccs c from ccsinfo.com one of the best IDE+C Compiler for PIC, or you can use the one from mikroeletronika it supports C, Pascal or Basic for PIC and AVR. – Diego Garcia May 15 '12 at 01:45
4

I suggest you check out FreeRTOS.

Oliver
  • 522
  • 3
  • 11
  • I saw that one and wondered about it. How would you compile, and save that to a PIC? Also I would need the RTOS to have support for detecting buttons and determining if a button had been pressed – Coder404 May 01 '12 at 21:00
  • Check out the "Supported MCUs" page for the supported tools. As for the buttons -- well, this would be your job to implement. – Oliver May 01 '12 at 21:04
  • See: http://www.freertos.org/a00090.html#MICROCHIP – Paul R May 01 '12 at 21:04
  • @Coder: A typical RTOS kernel provides priority based pre-emptive thread scheduling, inter-process communication and usually some minimal framework for interrupt handling. I/O is usually not included. In your case you might have the button input trigger an interrupt then the interrupt signal an event to a thread. Alternatively (and less efficiently) you might have a thread polling the inputs and sending events to other threads. – Clifford May 08 '12 at 22:20
2

I second the vote for FreeRTOS; we use this all the time on PIC24 designs. The port works well and doesn't use a ton of memory.

Microchip supports many third party RTOSes.

Most have free demo projects that you can download, build in MPLAB, and program onto an Explorer16 board very easily. You can then experiment to your heart's content.

Adam Casey
  • 949
  • 2
  • 8
  • 24
1

PIC is not a single architecture. PIC10 differs considerably from PIC24, though they and every PIC in between share some commonality. The MIPS based PIC32 on the other hand is an entirely different architecture. So you have to be clear about what PIC you are referring to.

An OS on a PIC does not have to be and RTOS, but that would be ideally suited to the application domain the devices are used in, so anything that were not real-time capable would be somewhat less useful.

There are many RTOS ports already for PIC.

There is nothing special about about a kernel scheduler in terms of development method, C and in most cases a little assembler are all that are necessary - no special tools. You could use 100% assembler if you wished, and this might be necessary to get the smallest/fastest code, but only if your assembler knowledge is better than the compiler's.

PIC is specific to Microchip, though Parallax SX is more or less a clone. Unlike ARM for example, Microchip do not licence the architecture to third-party chip manufacturers or IP providers. No one would want it in any case IMO; there are far better architectures. ARM Cortex-M is particularly suited to RTOS kernel implementation, and AVR's instruction is designed for efficient translation from C source code. Even the venerable 8051 is well suited to RTOS implementation; its eight register banks make context switches very fast (for up to eight threads), and like ARM, 8051 architecture devices are available from multiple manufacturers.

Coder404
  • 742
  • 2
  • 7
  • 21
Clifford
  • 88,407
  • 13
  • 85
  • 165
  • Thank You for your comment. I have decided to make my project FreeRTOS based on an ARM Cortex-M (due to your advice). – Coder404 May 08 '12 at 20:52
0

The hardware stack of PIC 18F CPU is only 31 bytes long. Other RAM memory cannot be used as stack. Even 8051 IRAM memory has 128 byte of stack. I have done RTOS for 8051, ARM and PIC 18F, and feels not good at PIC 18F. If the RAM(16K to 64K) of PIC32 can be used as stack, if the stack pointer is 16 bit long, it will be much better than PIC18F types. Does any one knows that?