Home‎ > ‎Electronics‎ > ‎

PIC


Development Tools

  • Microchip website that has a nice (and free) development environment www.microchip.com (MPLAB X IDE)
  • SourceBoost Technologies www.sourceboost.com/home.html offers a free limited code size C compiler with a very low cost upgrade policy for a unlimited memory size which support the 16 and 18 series processors.  They also offer a Basic and C++ compiler.  The simulation/debug environment is very good.  Code generation is much better than the free version from Microchip.  SourceBoost now offers a new free version that is 95% compatable and has no code size limits but I have not tried it yet.  It may work on some of the older projects which use SourceBoost for the compiler.

Links


Hanging Pen Drawing Machine




PIC project (MPLAB X): 
 StepHanger.X.zip  XCLib.zip is also needed (just the source StepHanger.c) (V2 7-21-2018)
                    DrawingMachineControl.X.zip  XCLib.zip is also needed (just the source DrawingMachineControl.c) (V1 7-21-2018)
PC Side Code: DrawingMachine1.zip (V0.3 6-02-2018)
Schematics: Tethered to PC: DrawingMachineBasic.pdf or Standalone: DrawingMachine.pdf
Devices: 18F1330 18F2620 (digikey or mouser)
Other parts: 
 Count      Name with link
 2 NEMA-17 stepper motor
 2 Easy Driver board (EasyDriver Shield Stepper Motor
 1 128x64 OLED display (LANMU 0.96" I2C)
 1 Rotary Encoder (KY-040)
 1 SD card socket
 1 Micro servo (HS-85BB)



This project draws a picture using a pen suspended from two pull chains that are attached to two stepper motors.  There are two versions of this project.  One uses a single 18F1330 microcontroller and is controlled by a PC.  The other replaces the PC with an 18F2620, an SD card, OLED display and rotary encoder to make a stand-alone system.  The PC software can load SVG formatted files like those produced by Inkscape and either drive the drawing machine directly or create drawing files that can be stored on an SD card and drawn later without a PC.


OLED Display



PIC project (MPLAB X): 
 OLEDdisplay.X.zip  XCLib.zip is also needed (just the source OLEDdisplay.c) (V1 7-21-2018)
Schematics: Not yet but it is the same as the two wire interface in this diagram on RB0 and RB1 with three resistors: DrawingMachine.pdf
Device: 18F2620 (digikey or mouser)

This example draws random graphics on a 128x64 pixel OLED display over an I2C interface.  The custom library created uses the memory in the PIC to act as the framebuffer for clean double-buffered display updates.  The performance is quite nice considering the serial interface to the display.

Servo Controller




LynxMotion

LynxMotion AL5D


PIC project:  CBServo2.zip  CBLib is also needed (just the source CBServo2.c) (V1.0 1-15-2015)
PC Side Code: ServoCnt.zip  common.zip (V1.0 12-05-2015)
Schematic: ServoController.pdf (V1.0 12-08-2015)
Device: 18F1330
This project is able to control 8 servos using a USB connection to a PC.  The code in the PIC implements spline interpolation for smooth transitions between positions.  The PC side code is a key frame animation system which allows manipulation of positions as well as the ability to tweak the spline bias controls.

This project was used with a Lynx Motion AL5D robot arm in order to control the motion of the arm.

Solar LED Light Controller

SolarLights.jpg

PIC project: CBBoostReg628.zip  (just the source CBBoostReg628.c) (V1.0 7-01-2015) 
Schematic: SolarLights.pdf (V1.0 7-07-2015) 
Device: 16LF628
This project replaced the failed control circuit in a solar LED string of lights.  The PIC runs down to 2.0V and makes a 4V power supply from two NiMH AA rechargeable batteries using a 100uH inductor and a bipolar transistor.  The PIC also senses the solar cell voltage to turn the string on at night and off in the morning.


Power Switch

    PIC project: PowerSwitch.zip  (just the source PowerSwitch.asm) (V1.0 5-29-2015) 
    Schematic:  PowerSwitch.pdf (V1.0 5-28-2015) 
    Device: 16LF628
    This project is used to turn on and off a small load (<100 mA) attached to a battery with a momentary push button.

Wii Nunchuck Interface


PIC MPLabX project: XCWiiNunchuck.zip (XCLib is also needed) (V1.0 4-16-2015)
PIC Sourceboost project: CBWiiNunchuck1330.zip (CBLib is also needed) (V1.0 4-16-2015)
Source: WiiNunchuck.c
PC side application plus source: WiiNunchuck.zip (V1.0 4-16-2015) Lib Code:  common.zip librnf.zip
Schematic: WiiNunchuck.pdf

This project interfaces to a WiiNunchuck to get button and joystick position as well as orientation of the device.  The PIC samples the X,Y and Z accelerometers and calculates the angle that the Nunchuck is pointing.  No special hardware is used on the PIC except for two generic I/O pins (no hardware I2C peripherals are required).  The PIC also performs some basic filtering to remove some jitter from the output. The USB interface is a Silicon Labs USB to 3.3V TTL board (available at Amazon.com for about $5 but needs drivers to be installed available at Silabs.com). The interface board for the Wii Nunchuck is available from Sparkfun Electronics.


Auto Off

    PIC project: CBAutoOff.zip  CBLib is also needed (just the source CBAutoOff.c) (V1.0 4-23-2014) 
    Schematic:  AutoOff.pdf (V1.0 4-05-2014) 
    Device: 18F1330

    This project is used to turn on and off amplified speakers so that they are only on when the TV that they are hooked up to is on.  The audio output from the TV is sampled to detect when the TV is on.  The power is switched using a solid state relay.  The project was placed in an old Radio Shack audio switch box to take advantage of the RCA jacks.

Stepper Motor Control

PIC SourceBoost project: CBStepper.zip  CBLib is also needed (just the source CBStepper.c) (V1.0 7-27-2013) 
PIC MPLABX project: XCStepper.X.zip  XCBLib is also needed (just the source XCStepper.c) (V1.0 3-25-2014) 
    Schematic:  NoneYet.pdf (V1.0 7-20-2013) 
    Device: 18F1330
    This project independently controls three stepper motors using a cheap processor and some high voltage transistors

Logic Analyzer 2
https://www.sites.google.com/site/tedrossin/home/electronics/xilinx#TOC-Logic-Analyzer-2

Device: 18F2620 Xilinx XC9572XL CPLDs.
Details can be found on the Xilinx page Logic Analyzer 2 or click the picture above.
Other Logic Analyzers: Very old   Very simple and cheap

This project uses a couple XC9572XL 5V tolerant CPLDs, some static RAM, a PIC microcontroller and some glue logic to form a 24 channel 32K deep 30ns per sample logic analyzer.  The sampling rate can be varied from 30ns to 250us and can also be controlled by an external clock with selectable delays and dividers.  The machine also has 3 primitive 0 to 5 volt meters and has a 5V TTL compatible programmable clock generator which can go from 100 Hz to 2.5 MHz.

More details can be found on the Xilinx page here.

SD Card Interface

    PIC project: CBSDFileSystem.zip  CBLib is also needed (just the top level source CBSDFileSystem.c ) (V1.0 1-07-2014)
    PC side code for remote mode: SDFs.zip   common.zip is also needed for serial port functions.
    Schematic:  SDInterface.pdf (V1.1 6-25-2019 [Updated SD connections to be more clear])
    Device: 18F2620
       
      This project connects an 18F2620 to a 3.3V SD card and is able to access FAT12, FAT16 and FAT32 file systems with long filename support.  MMC, SD and SDHC cards are supported and cards from 16M bytes to 8G bytes have been tested.  Both remote and local access is provided with examples of each such that the code can be used as a base layer for a project which needs the ablitiy to read and write SD cards or the code can be used as is with high level access via the serial port.  The common C functions FsOpen, FsSeek, FsRead, FsWrite and FsClose are used to open a file to read or write.  There are also functions to change and get the current directory name as well as to read the directory to see what files are on the card.  Files and directories can be removed as well as created.  The file SDFs.h has a variable defined named LOCAL_MODE.  Comment this line out for remote access.  The default build is local mode which has a little application to simulate a unix command prompt via the RS-232 port.  Program up the PIC, build the circuit, insert the SD card and power up the PIC then open up a terminal to it and hit enter to get the PIC to mount the SD card.  The PIC will mount the SD card and list the commands that you can enter.
       
        ls                will list the current directory (the attributes are listed as 3 letters drw.  d is - for plain files and d for directories)
        cd path      will change the current directory to that given in path.  For example:  cd Zero 7/Simple Things
        pwd            will display the current directory path
        cat filename    will echo the file to the terminal window.  Not a real good idea to do on binary files.  For example:  cat ../../TedDir/CBSDfileSystem.c


      For remote mode, the Visual C++ project SDFs.zip has a file named SDLearn.cpp which implements a fake command line shell like local mode but interacts with the PIC using a serial interface.

      Sector caching is implemented and the amount of memory allocated to it can be controlled as well as the number of open files allowed with the following defines that can be found in SDFs.c:

        #define CACHE_SIZE   5
        #define NUM_FD   4

      If your application needs more RAM, reduce the CACHE_SIZE as each count uses 512 bytes of RAM.  The sector cache helps out when there are multiple files open at once and also helps cache the File Allocation Table (FAT).  It will also be used for a write buffer.

      This has been a fun project in that I got to learn a lot about Microsofts's FAT file system and how they squeezed long filenames into a very old format.


Touch Screen Keypad

                                  https://drive.google.com/file/d/0B0Ai_TrfkxYEUXBVV1dxcUxQRGM/view?usp=sharing    https://drive.google.com/file/d/0B0Ai_TrfkxYEd1BYWDNMS3FGems/view?usp=sharing
Click images for larger view

PIC project: CBTouchHex.zip (just the source CBTouchHex.c ) (V1.0 11-24-2011) 
Schematic:  TouchKeypad.pdf (V1.0 11-24-2011) 
Device: 18F4620 
 
  • This project implements a hex keypad using a Nintendo DS touch screen which I purchased from Sparkfun Electronics.  I use this keypad to interface to a clone of my first computer which can be found here Elf Clone.  The touch screen is clear so I printed out my desired virtual keypad onto a piece of paper (the Microsoft Word document is included in the zip file) and placed this under the touchscreen.  To add some visual feedback, I placed an array of LEDs under this piece of paper.  The LEDs are inserted into a thin piece of plywood which can be seen in the photo on the right (click it to see a larger view).  I used Elmer's glue to hold the LEDs in place and hot glue to hold the PIC in place.  I bent the pins out to solder it up.  It is ugly but pretty stable.  The case is just an old picture frame that I found which fit nearly perfectly.  This could all be done on a double sided board using surface mount parts to make it very skinny.  My keypad ended out being about one half inch thick.
  • The top four buttons as well as the DEBUG button are toggle buttons so the LED under them will toggle between on and off when the corresponding button is pressed.  All the other buttons just flash the LED when they are pressed.

Duck House Controller


 Display on outside of the duck house Controller inside the duck house
  
The boys outside their house in their run. That is not the house they sleep in at night.  Their house is 8x10 feet. Temperature log display after samples have been collected
Click images for larger views

PIC project for Controller: CBDuckHouse.zip (just the source CBDuckHouse.c ) (V1.0 3-10-2011)
PIC project for Display: CBDuckDisp.zip (just the source CBDuckDisp.c ) (V1.0 12-21-2010)
Schematic:  DuckHouse.pdf
Device: 18F4620 for controller and 16F628 for display (source compiled with SourceBoost C compiler).  Also uses two TC77 serial temperature sensors.
Host Code to download and display temperature data: TempLog.zip
This project is used to log temperature inside and outside our duck house.  The project also includes a numeric 2 digit LED display which is controlled by a synchronous serial interface to display the inside temperature so that it can be seen from the house using a spotting scope.  The samples and time are saved into the flash memory of the 18F4620.  The Host code connects to the controller via RS-232 and is able to set the current time and sampling rate.  The host code is able to download samples and clear memory after the sample have been recorded.  In the display above, the purple wave shows the outside temperatures and the white wave shows the inside temperatures.

Clone of 1976 Popular Electronics COSMAC Elf using two PICs

RCA

Device: 18F4620 to emulate CDP1802 processor and 18F2620 to emulate CDP1861 video chip.
This is a bus accurate full speed Elf created without an 1802 or 1861.  This project is able to load a programs via dip switches (and now a hex keypad) and execute it.  More details can be found here ElfCone.

Cassette Interface

Click image for larger view

PIC project: CBCassetteInt.zip (just the source CassetteInt.c ) (V1.0 1-31-2007) 
PC Side Code: CassetteInt.zip  common.zip 
Schematic:  CassetteInt.jpg (V1.0 7-16-2007) 
Device: 16F876A 

This project replaces a cassette recorder which was used for program and data storage for a vintage computer with a box and an RS-232 interface to a modern computer.  This allows old programs and data to be saved as ASCII hex files and then later played back.  The PIC processor A/D block is used to sample the REC input and convert the serial data to 8-bit binary numbers.  These values are saved in RAM and then set to the modern computer via the RS-232 interface.  The speaker out jack is driven out to the vintage computer in response to commands sent from the modern computer from the RS-232 interface.  The timing and voltage settings have been hard wired for my first computer using constants but a slight change to the PIC code could be made to allow the values to be changed via host PC side software.

Here is a link to my first computer that uses this machine.

Camera Controller

 Controller hanging below camera Camera fitted with actuator Controller Inside the controller
Click on images for larger views
    PIC project: CBTimelapse.zip (just the main source TimeLapse.c)  (V1.0 10-25-2006)
    Schematic:  TimeLapse.jpg
    Device: 16F876A
     
      This project controls my old cannon S10 digital camera using a soleniod to take pictures during a specified time at a specified rate.  The images are then processed to create a movie that can be played on a computer or authored onto a DVD.  A serial port is included to allow the firmware to be upgraded or used for direct computer control or to allow custom time tables to be downloaded.  My dream is to hook ups some stepper motors to be able to control the view as well one day.
Below are some videos I created with the camera.  I used ImgConvert to convert the pictures into an MPEG (Motion Picture Experts Group) video before uploading to YouTube.

YouTube Video

YouTube Video




    Cheap Logic Analyzer


     
     
     
    Old Version New Version Voltmeter mode 
    Click on images for larger views

    My other logic analyzers

    Very Old:  CDP1802CD CMOS processor built in 1985 using 1970's Technology
    More features: CPLD based 32K sample, 24 channel with 30ns/sample sampling rate
     

    Latest Version

      This is a very cheap logic analyzer that can be built for about $10 that works with 3.3 to 5V logic.  The hardware is simply a 18F2620 with 10 MHz crystal and an RS-232 interface or FTDI USB to 5V TTL cable (available at Sparkfun.com for about $18 no drivers needed) or Silicon Labs USB to 3.3V TTL board (available at Amazon.com for about $5 but needs drivers to be installed available at Silabs.com).  The specs are not great but it can be used to solve many problems.  I found it very useful for debugging an antique computer as well as serial interfaces.

      There are 5 analog inputs that can be used as volt meters that are displayed on the screen in real-time.  Run length encoding was implemented for a simple compression scheme to get faster updates.   New to version 4.02 and above is the ability, when using the FTDI USB to 5V TTL cable or USB to 3.3V TTL board, to run the serial port at 8x the normal 115K baud rate.  To enable this feature, select the Configure menu then select "Enable Fast Serial".  The setting will be remembered in the registry.

      A square wave generator output has been added which can be set from 2.44 KHz to 2.5 MHz.  This output, if enabled, is driven on port C bit 1 (RC1).
       

      Number of Channels
      Number of Samples
      Max Sample Rate
      Min Sample Rate
      8
      3936
      200ns/sample
      250us/sample
    Old Version
      PIC project: CheapLA.zip (just the source CheapLA.asm )  (Version 2.01: 12-21-2008)
      PC side Code: LogicAnalyzer.zip (Version 3.05: 3-01-2014 Note that this is the same as the new version above)
      Schematic: CheapLogicA.pdf
      Device: 16F873, 16F873A or 16F876A
       
        This is a very cheap logic analyzer that can be built for about $10.  The hardware is simply a 16F873 with 20 MHz crystal and an RS-232 interface.  The specs are not very good but it can be used to solve many problems.  I found it very useful for debugging an interface to a serial EEPROM.
         
        Number of Channels
        Number of Samples
        Max Sample Rate
        Min Sample Rate
        8
        96
        400ns/sample
        -
        81601us/sample20ms/sample
        4
        320
        2us/sample
        20ms/sample
        2
        640
        2us/sample
        20ms/sample
        1
        1280
        2us/sample
        20ms/sample


    LCD Terminal

                         
    Click on images for larger views
      PIC project: LcdTerminal.zip (just the source LcdTerminal.asm)
      Schematic:  LcdTerminal.jpg
      Device: 16F628
       
        This project controls a 20 character by 4 line LCD display so that a simple serial RS-232 or TTL interface can treat the display as an ASCII terminal.  The source code explains all the control characters and escape sequences to control scrolling the display, clearing the display, downloading custom characters and other features.  The interface runs at 115K baud by using a software FIFO to handle input characters during a vertical scroll.  A select pin is provided that allows the interface to run at 9600 baud.
      Demo:
          SourceBoost Project: CBMeter.zip (just the source CMeter.c )
          Library of C routines:CBLib 
       
        This is a demo program that uses a 16F873 and the LCD Terminal to implement a volt meter.  The CBLib.zip file is required as well as the SourceBoost C compiler.  See the Lego Robot Controller below (or use the index at the top) for details.

    Lego Robot Controller

      
    Click on images for larger view
      Library of C routines: Library of C can be found below (or use the index at the top of the page) 
      SourceBoost project 1: CBLegoBumper.zip (just the source Bumper.c)
      SourceBoost project 2: CBLegoCrane.zip (just the source Crane.c)
      Schematic: LegoController.jpg
      Device: 16F877
       
        This project controls Lego robots in a way similar to Lego Mindstorms. Two dual H-bridge chips(L283) are used with the PIC microcontroller to control 4 motors.  Each motor has speed, direction, float and brake control.  Eight A/D inputs are sampled sequentially and the motor PWM control is done in an interrupt routine so that user code can treat the inputs and outputs as continuous values.

        User level control is done in C (compiled with the SourceBoost compiler). The controller is packaged with 8 Lithium-Ion AA batteries in a brick of legos using no glue or special parts.  Programming is done through a RS-232 port using the Serial Port PIC Boot Programmer described below.

        This is really cool stuff.


    Funky Digital Clock

    Click on picture for larger view
    PIC project: FunkyClock.zip (just the source funkyclk.asm) (V1.0 3-28-2002)
    Schematic: FunkyClock.jpg
    Device: 16F84A
    This project uses the same circuit as the Digital Clock below but runs at 4 MHz and uses different software to add some visual effects.  The time is displayed for a random amount of time followed by one of several effects for a random amount of time.  This loop is repeated.

    The stand is made from the metal brackets of a file folder.  The large 5V regulator below the display has been replaced with a smaller TO-92 case 78L05 regulator.


    Digital Clock

    Click on picture for larger view
    PIC project: Clock.zip (just the source clock.asm )
    Schematic: Clock.jpg
    Device: 16F84A
    This project uses a 3 and a half digit 7-segment LED display from a broken bread machine to show the time of day.  The non-resetable TRM0 timer (if it is reset time drifts)  is used to generate interrupts at a rate of 610 and 45/128 Hz using a 20 MHz crystal (488 and 9/32 Hz using a 4 MHz crystal).  This is the display refresh rate.  The interrupts are counted to get seconds, minutes and hours using some games to implement the fractions.  The time is set using two push button switches that are scanned using the digit drive enables and sampled using a free input pin.  This circuit consumes less than 20mA at 5V using a 20 MHz crystal.

    Serial Port PIC Boot Programmer


    PC side Code: PicBootProg.zip (Source code:  PicBootProgSource.zip  [V 2.0 11-22-2010])
    Lib Code: common.zip
    18F PIC project: BootLoader_18F.zip (just the source Bootload_18F.asm )  [11-18-2013]
    16F PIC project: BootLoader.zip (just the source bootload.asm )  [9-22-2008]
    Schematic: None.  Just software
    16F Devices:  16F87x and 16F87xA and 16LF versions
    18F Devices:  18F1230, 18F1330, 18F2620 and 18F4620
    This project allows flash based PIC microcontrollers to be programmed using a simple in circuit serial interface once the device has been programmed with the code supplied.  The RS-232 interface needs to be connected to the standard RS-232 pins of the device PORTC[TX] and PORTC[RX].  In addition to this connection, PORTC[2] is used to select, at power up, whether to run the user program (low) or to run the boot loader code (high).  The 16F device must be running with a 20MHz crystal but other frequencies could be used with a slight modification to the baud rate value in the boot loader.  The serial transfer rate is 115K baud.  Slower frequencies may require the baud rate to be reduced which would require the PC code to change as well.  The 18F devices require a 10 MHz crystal with the PLL enabled (40 MHz operation).  Refer to the assembler code to figure out which pin is the boot pin.  Also supports internal OSC with PLL enabled (32 MHz operation).

    Note that the last 256 words or less of program memory are used by the boot loader depending on the device.  The first 4 word locations of the user program can be used as they are copied into the bootloader space by the loader while it then puts a jump into the first few locations.

    This bootloader works with code produced from BoostC for both the 16F and 18F devices.


    Serial Port PIC Programmer

    Just get a PICkit 2 or PICkit 3 to program devices.
    Click on picture for larger view
    PC side Code: picprog.zip (Source code:  HostPicProg.zip   Lib Code:  common.zip)
    PIC project: SerialProg.zip (just the source serprog.asm )
    Schematic: PicProgrammer.jpg
    Device: 16F84A or 16F628
    This project allows flash based PIC microcontrollers to be programmed using the serial port on a PC.  The serial interface runs at 115K baud.  I found parallel port connection solutions to be flaky and dependent on which PC/OS was used so I made my own.  The only bummer is that you need to program a 16F84A to build this programmer.  Only locations that need to be modified are programmed to limit the erase/program cycles and speed up programming.

    This updated version now supports 16F87xA as well as the non A versions.


    Library of C Routines

    Library of C routines: CBLib.zip
    This zip file contains the following files: 
    clock.c clock.h
    clock18F.c clock18F.h
    Code to implement a real-time clock plus functions to perform math on time in day, hour, minute, second format.  This code also includes the ability to trim the clock to make up for crystal errors.  I've tuned to a 1 second error ever 3 or 4 days.  Without triming, the error can be as high as 10 to 20 seconds per day.  Most crystals are accurate but have a fixed error from their stamped frequency of 20 parts per million.  Do the math.  It is a big error when being used as a clock.
    ExtEeprom.c ExtEeprom.h Code to interface to an external serial EEPROM.  Just change the defines at the top of ExtEeprom.c to use any two pins for the interface.
    Lcd2Line.c Lcd2Line.hCode to interface to a 2 line by 16 character LCD module using 6 pins.
    Lcd.hHeader file for interfacing to a the serial 4 line by 20 character LCD terminal described above.
    legocore.c legocore.hCode to implement PWM conrtrol and direction of 4 motors as well as sampling 8 analog channels.  This code is used for the Lego Robot Controller project described above.
    Serial.c Serial.h
    Serial18F.c Serial18F.h
    Code to implement RS-232 interface using PIC hardware.
    String.c String.hCode to implement a limited version of sprintf (sprintf1, sprintf2 .. sprintfx)
    Timer.c Timer.h
    Timer18F.c Timer18F.h
    Code to implement delays using hardware timers and interrupt.
     

    SourceBoost Plugins

     The following plugins are for use with the SourceBoost IDE:
    DescriptionPlugin V6Example V6Plugin V7Example V7
    Active Low push buttonsBoostDigIO.zipCBButtonTest.zip

    4 Channel Pulse Width Modulation monitorBoostPWM.zipCBPWMTest.zipBoostPWM7.zipCBPWMTest7.zip
    Value Change Dump (VCD) sampler.  This plug in allows all the ports (A through E)  of a PIC to be sampled into a file during simulation.  This file is formated to allow it to be read by ECAD tools in order to display a graphical representation of the signals over the length of the simulation.  For a VCD viewer, click this link to get one I wrote a few years back:  VcdView
    V0.2 
    1-21-2010

    TedsBoostVcd

    CBSimple2.zip
     V0.2 
    1-04-2012

    TedsBoostVcd7



    Comments