Cool Cap Engineer

Engineering by an anime nerd

Leave a comment

Mini Projects: 15 Watt Audio Amp Experiment

A couple weeks ago, I mentioned that I was learning how to build audio amps and I tried building one using Sparkfun’s STA540 audio amp kit. Well, I tried to design the PCB for my modified version of Sparkfun’s audio amp kit, but I ran into a very….large problem. In order for me to make sure the STA540 properly drives two speakers at 25 Watts, I needed a multiwatt heatsink. However, the heatsink takes up 1/3 of the PCB! Not to mention it will be a pain fitting it inside a box since the heatsink is also very tall! In otherwords, I needed to find something else.


Then I heard about the TPA3122, a 15 watt stereo audio amp.  Although it can only drive 10 watts less than the STA540, the space it saves more than makes up for it. After building the circuit, I ran into latching issues, or when the ic stops working due to voltage spikes on the dc bus. At first, I thought adding more bulk capacitance would help, but it had no effect. After asking around, one person suggested to rewire the circuit to be much more orgainized. Not only did I rebuild my circuit on the breadboard, but I place .1uF decoupling capacitors as close to the IC as possible. Afterwards, the amplifier worked marvelously! I even recorded a video of the amplifier in action.

Suffice to say, I will consider using the TPA3122 for my next audio project. Well, that’s all from me today! If you have any suggestions, comments, or concerns, please feel free to use the comments below. See you guys again next week!

Leave a comment

Tutorials: Simple Electronic Load Circuit


Electronic load on bench. Drawing close to 1.20A at 21V

A couple weeks ago, I had a discussion with one of my co-workers about electronic equipment. I complained that alot of the equipment that I want is very expensive. I told him some of the requirements that I’m looking for. After a couple minutes talking, he said to me “Why not build it yourself? The requirements are not that stiff.” “Crap, he’s right”, I said. After couple weeks researching the topic and brushing up on Mosfets, I built a very simple one. There is a alot of refinement that could be done on the circuit, but it demonstrates the topic nevertheless.Today’s post will talk about how this electronic load circuit works and how to build one yourself.

What is an electronic load?
An electronic load is a device design so a power supply can draw a certain amount of current without desipating tons of heat. Electronic loads are useful for testing a power supply’s efficiency, current limit, etc.To understand how the circuit works, I’ll talk about two crucial things involving mosfets and op amps. Let’s talk about the mosfet aspect first.


VDS vs ID characteristics. Shows the mode we want to operate to behave as an electronic load.

Although the picture above looks like a bunch of lines for hobbyists, this VDS vs Id characteristics shows how the mosfet will behave depending on the voltage applied at the gate and source (VGS for short) Mosfets have 3 modes of operations: cutoff, active, and saturation. When the mosfet is in cutoff operation, it does not turn on. This is due to the voltage applied to the gate and source  not high enough to turn it on. Active is a state in which the mosfet’s gate has enough voltage to allow the mosfet to behave as a variable resistor. Finally, saturation is when the mosfet behaves like a switch. For this load to work, we need it to enter active mode since we can set the mosfet to draw a certain amount of current.


Now let’s talk about one common configuration using an op amp: a unity amplifier. The sole purpose of a unity amplifier is to make sure that the voltage seen at the non inverting pin of the op amp (+ pin) appears at the output. Although it sounds simple, these amplifiers are useful to prevent the input source from getting affected from output impedance. However, we will be using this configuration for another reason.


Electronic load schematic

Now let me explain how the circuit works. First the user sets the voltage using a potiemeter (R2 in the schematic) and gets set at the inverting pin (- pin).  Although the op amp looks like its configured as a comparator, it’s actually set as unity amplifier due to the mosfet. To make sure the voltage at the non inverting pin appears at the inverting pin, the op amp must set a certain voltage to the mosfet gate. Depending on the gate voltage, the mosfet will draw a certain current until the voltage at R1 is equal to the voltage at the non-inverting pin.


How to select your mosfet?
Unlike my other tutorials, there’s a high possibility you’ll damage the mosfet in this tutorial, if you’re not careful. When looking at the datasheet for a mosfet, remember to pay attention to the drain current (ID) and drain to source (VDS) ratings. ID determines how much current the mosfet can handle before exploding and VDS determines the maximum voltage that can be applied for safe operation.


BUZ11 safe operating area per datasheet

Now for the little known parameter you should REALLY look at when reading mosfets datasheets: the safe operating range (SOA). Keep in mind, mosfets liked to be switched on and off. Rarely do you want the mosfet to work with analog voltages. The SOA tells you the recommended voltage and current that the mosfet can handle before exploding.

Build Your Own!

The following circuit is designed to handle 20V from 0A-5A. You’ll need the following to build this circuit

1x 10k Poteimeter

1x Buz11 Mosfet

1x 10Watt TO-220 Resistor

1x 741 Op Amp

2x .1uF Capacitors

2x Heatsinks

1x breadboard

Misc. wires

1x Cooling Fan (optional)

Consequentially, you’ll need the following tools for this circuit

1x +15V/-15V power supply

1x +32V/5A Power Supply

1x Mulitmeter


Now assemble the circuit as shown in the picture below. Remember to attach the heatsinks to the resistor and mosfets! THEY WILL GET DAMAGED WITHOUT THE HEATSINKS! If you have a cooling fan lying around, turn it on and direct it towards the resistor and mosfet. The colder these components run, the less likely they will get damaged.


Before Turning The Circuit On.
Do not apply 20V to the mosfet just yet.You want to make sure the voltage at the poteimeter is 0V, otherwise your power supply will go into current limit.  Apply power to the op amp/poteimeter. Make sure the voltage at the poteitmeter is 0V. Now apply power to the mosfet and start turning the knob. You should start seeing the circuit consuming a certain amount of current will keeping the voltage of the power supply the same.


Well that’s it for today! Thank you guys for reading this post and if you have any questions, comments or concerns, please post a comment. Also, be free to follow me on twitter. Have a wonderful week!

Leave a comment

Tutorials: Op Amp Relaxation Oscillator


Relaxation oscillator on the bread and waveform taken on oscilloscope.

So lately I’ve been messing around with op amps. Why? Because I want to learn more about oscillators and wanted to build one from scratch. One of the simplest oscillator to build using an Op Amp is a relaxation oscillator. Today, I’ll talk about how it works and a small experiment using the oscillator.

What is an oscillator?
An oscillator is a circuit designed to output a repetitive signal over and over again based on a certain frequency. Oscillators are often use for devices such as switching regulators and making sure your PC’s CPU operates correctly. Some of the waveforms an oscillator can output includes square waves, sine waves, sawtooth waves, triangle waves, etc. Today’s relaxation oscillator will output a square pulse with a 50% duty cycle.

How does A Relaxation Oscillator work?

Relaxation Oscillator Schematic

Relaxation Oscillator schematic

An Op-Amp relaxation oscillator is comprised of two parts: a schmitt trigger and a RC  circuit (R3 and C1). When the circuit is powered, it charges the capacitor in the RC network. Keep in mind that whatever voltage appears at the capacitor will appear at the non-inverting pin of the op-amp (pin 3). The schmitt trigger (R1 and R2) determines when the output will swing from high to low or low to high.  In other words, the schmitt trigger determines when the capacitor will start charging or discharging.


Output waveform (yellow) and the charging voltage of the capacitor (blue)

The figure above was taken from an relaxation oscillator with 15V peak to peak voltage. Although it shows 30V peak to peak, the DC offset of the waveform was set around 15V. Nevertheless, you can see that when the capacitor is charging, the relaxation oscillator output goes high, and goes low while the capacitor is discharging.

The frequency of the waveform can be set using the following equation:


Keep in mind, these equations work under the assumption that the voltage on pin 8 and 4 of the op amp are symmetrical. For example, if you apply 9V to pin 8, then -9V should be applied to pin 4. Also, if you apply 15V to pin 8, then -15V should be applied to pin 4.

Build Your Own!
Although I now have an oscilloscope – a crappy one, but still an oscilloscope- I realized some of you guys probably do not have one. So, I devised a small circuit that will turn on flash two LEDs on and off every 250ms. You will need the following materials:

1x DC Power Supply (Able to supply +15V and -15V)
1x LM741 Op Amp
3x 1K Ohm Resistors
2x .1uF Capacitors
1x  10K Resistors
1x 1uF Capacitors
2x LEDs
1x Breadboard
Misc. Wires

Now wire the circuit like in this picture.

relaxation oscillator circuitNow power up your DC power supply! You should see the LEDs flash on and off. The purpose of the LEDs is to show that the oscillator is outputting a square pulse with a positive and negative amplitude.



Well that’s it for today’s post! If you have any questions, comments, or concerns about today’s post, let me know. Thanks for reading, and see you guys next week.


Leave a comment

Mini Projects: Boost Converter Experimentation

Since I started working in the power electronics industry, I figured I should spend a little more time building power electronic circuits. I remembered that I understood how non-isolated boost converters worked during my school work and decided to build one for myself.  For those who do not know, a boost converter is a power electronic circuit that converts incoming voltage to a higher voltage. I decided for starting purposes, I would build a 12V to 24V boost converter. Although I plan to write a tutorial which shows how boost converters work,  this post is to talk about what I did in my free time.


12V TO 24V Boost Converter Schematic

After a week relearning important boost converter design parameters, I managed to draw out the basic schematic. Although there are 3 components missing from my schematic, those parts functioned as a way to implement a controller for the boost converter. There are alot of major improvements that could be made, such as protecting Q2 from high voltages, solving the logic inversion caused by Q1, and prevent L1 from causing my power supply to current limit. However, I just want to see the boost converter work.


Boost converter circuit soldered onto a perfboard

After buying my parts from Digi-key, I soldered my parts to a perfboard. Why not assemble the circuit on a breadboard? In order for this  boost converter to properly work, I needed to switch the main transistor (Q2 in the schematic) at a high frequency (I based my calculations around a 62.5KHZ switching frequency). Since I’m switching at a high frequency, building the circuit on a breadboard will screw up the signal due to the breadboard’s nature of acting as a capacitor at high switching frequencies.


The boost converter load

Finally, to make sure the boost converter functions correctly, I needed to connect a load. I decided to go with a 25 ohm/50W resistor. If the boost converter was not connected to a load, then there’s a high chance the boost converter will go unstable. A high value resistor can be connected at the output to function as a dummy load to prevent the boost converter from going unstable. Also, I was dissipating a lot of heat through this resistor. The resistor got so hot that it melted one of my oscilloscope clips.


Blue waveform is the output at the load, while yellow is the square pulse going into the the Q1.


So I was ready to power up my converter. Since I was using my multimeter as a current meter, I had to setup my crappy Hantek oscilloscope to measure the voltage by measuring the DC level. One thing that surprised me was the actual duty cycle needed to set the voltage to 24V. To get 24V, instead of setting my frequency generator to 62.5KHZ with a 50% duty cycle, I got a 24V output  using the same frequency, but a 25% duty cycle. This usually happens when your boost converter is incredibly inefficient. Brother, my boost converter was the definition of it. According to my calculations, my boost converter efficiency was around 70%.Well…it was a good attempt, but converter needs a lot more work. I will need to investigate the causes of the low efficiency, and rectify it. My first suspicion involves the big bulky inductor. The bigger the inductor, the higher the parasitic resistance.

Thank you guys for reading this post, and if you have any suggestions on how I can improve the efficiency, then leave a comment below!

1 Comment


Buck regulators are used for reducing the input voltage coming from a power supply to safely power microprocessors, gate drive circuitry, and other circuits. Today, I will show you how to use the LTC3639 – a buck regulator that can receive up to 150V- which comes with under-voltage and over-voltage lockout.

The LTC3639 should allows you to to easily change the output voltage, undervoltage lockout, overvoltage lockout, switching frequency, and the maximum peak current. I built 15V power supply using the LTC3639 and the DC1901A development board from Linear Technology.

Pin Functions


  • SW (Pin 1): Connects to the drain of the LTC3639’s internal MOSFET.
  • Vin (Pin 3): Supply pin for the IC
  • FBO (Pin 5): Feedback comparator output. Connect to VFB of other LTC3639’s in order to increase the output current. Otherwise, leave FBO floating.
  • VPRG2, VPRG1 (Pins 6, 7): Used for configuring the output of the LTC3639. These pins can be connected to either ground or the LTC3639’s SS pin.
GND GND Adjustable
SS SS 1.8V
  • GND (Pins 8, 16, 17): Ground connection. Pin 17 must be soldered to the PCB ground plane for rated thermal performance.
  • VFB ( Pin 9): Output voltage feedback. Connect to output voltage’s resistive divider for an adjustable output. Connect this pin to Vout for fixed output configurations.
  • SS (Pin 10): By connecting a capacitor from this pin to ground, the voltage ramp up time can be set. Leave floating to use internal 1ms soft start.
  • Iset (Pin 11): Leave this pin floating for 230ma peak current. Short this pin to ground for 25ma peak current. For a configurable peak current, connect a resistor from this pin to ground.
  • OVLO (Pin 12): Can be used to configure the overvoltage lockout using a resistive divider connected from the input supply. If the voltage on this pin is greater than 1.21V, then the overvoltage lockout is activated. The chip resumes operation when the voltage on the OVLO pin is less than 1.10V.
  • Run (Pin 14): Activates the chip when the voltage on this pin is greater than 1.21V. This pin shuts off the chip when the pin’s voltage is less than .7V. The Run pin is also used for setting the under voltage lockout.

Leaving  pin 12 floating sets the peak current to 230ma, while shorting this pin to ground sets the peak current to 25ma. For a different current peak current limit, a resistor should be connected from pin 11 to ground. The peak current cannot exceed 230ma and cannot be less than 20ma. The peak current is also twice the average current. The value of the peak current resistor can be found using the following equation…

The inductor is used to determine the LTC3639’s switching frequency when it is operating in burst mode, or when the LTC3639 is lightly loaded. The following equation is used for determining the inductance during burst mode.

If the LTC3639 will not be lightly loaded, then the inductor must meet the following two conditions…

Although the previous equations provide some insight on how the inductor will affect the switching frequency of the LTC3639, figure 2 gives a range of recommended inductor values given peak current for maximum efficiency.


It is recommended to use ferrite core inductors for their ability to handle a high switching frequency, and low core loss.

An input capacitor is necessary for filtering the trapezoidal current going into the source of the LTC3639’s internal high side MOSFET. If the maximum input voltage ripple is given, then the following equation can be used.

The output capacitor is needed to filter the inductor’s ripple current. If the desired output voltage ripple is given, the output capacitor can be selected as long as it follows the following two conditions…

How the output voltage is configured depends on the configuration of VPRG2 and VPRG1. For an adjustable output voltage, short VPRG2 and VPRG1 to ground, and connect VFB to an external resistive divider from the output. The output voltage can be set according to the following equation.

The only requirement on the resistive divider is to keep R2 less than 200K in order to keep output voltage variation less than 1%.


The undervoltage, and overvoltage lockout can be set using a three resistor divider.


All three resistors must satisfy the following condition…


By leaving pin 10 floating, the output voltage ramp time will typically be 1ms. If a longer ramp time is required, then connect a capacitor from pin 10 to ground. The value of capacitor can be computed from the following equation…

Although the ramp time can be calculated from C_ss, it must fulfill the following condition…


I used the LTC3639 to assemble 15V power supply circuit to power a gate drive circuit I was working on. The 15V power supply must perform according to the following requirements…

Overvoltage Lockout=97V
Undervoltage Lockout=18V

One of the first tests performed on the 15V circuit was loading it with a 100ma load and observing the start up time. It took 12ms for the output to start up after immediately applying 43V and 85V to the 15V power supply circuit.For more information about the LTC3639, look at the datasheet. Feel free to post a comment if you have a question or concern. Once again, I will see you guys next week!

Leave a comment

Projects: Arduino 24V Brushed DC Motor Controller Shield Update #2


In my last post, I talked about my newest project; a 24V DC brushed motor controller shield for the Arduino. I mentioned my setbacks in my post and that in my new post, I will give an update for the project. Unfournately, the only thing I could do last week was replacing my old Arduino Duemilanove with the Arduino Uno. Until I can test the circuit proper, I decided to spend this post discussing how I intend to control this 24V motor.


If you’re a regular visitor of this blog, an electrical engineer, or just an electronics hobbyist, then you’re probably familiar with an Hbridge. An Hbridge is an electronic circuit that changes the direction of current flowing to a motor in order to change the rotation its shaft. To change the flow of current, four switches are used. Using the figure 1 as a reference, the motor’s shaft rotates clockwise when S1/S4 turns on, and when S2/S3 turns on.

Today, these Hbridge switches are replaced with transistors. Lower voltage Hbridges can be made using Bipolar Junction Transistors (BJT) since they require little current to properly control lower voltage motors. However, if you’re control 12V and more motors, then BJTs would be horrible as they will require more current to control these motors. So instead, metal oxide semiconductor field effect transistors (MOSFET) are used since they “ideally” consume no power to turn them on. For motor control, Power MOSFETs are used. There are two types of MOSFETs: Pchannels and Nchannels. I will not discuss the physical difference between them, but I will mention that Nchannels turn on when you apply a positive voltage to its gate, and Pchannels turn off when you apply positive voltage to its gate.

Alas, MOSFETs also have problems to consider. One problem is that if you try to pass 12V or more through the Nchannel MOSFET, then you need at least 12V to turn them on. Also, to turn off a pchannel, you to apply the same voltage you’re sinking through the MOSFET to its gate. I seen many forum posts in which people blown out their MOSFET forgetting this important fact. Of course I’m no different since I made the same mistake senior year of college…and in my last post.

Now that I talked about the theory of this motor control, let me talk about my proposed circuit. In my Hbridge circuit, I have my upper switches comprised of pchannnel MOSFETs and my bottom switches made up of nchannel MOSFETs. To turn on just one pchannel MOSFET, the Arduino will activate a low current NPN transistor, which will turn on the pchannel MOSFET because of the voltage divider at its gate. However, when the NPN transistor is off, then the voltage at the pchannel’s gate will be equal to the voltage being applied to it. By having the voltage applied to equal to the voltage at its gate, the Pchannel turns off. This method is repeated for the other pchannel MOSFET.

Finally, to control whether an nchannel is off or on, 12V-20V must be applied to the gate. Unlike a pchannel MOSFET, the voltage applied to the gate can be a separate voltage from the vvoltage applied to it. To accomplish this, I used low side gate drivers (IR4427) to provide the right voltage to turn the bottom Nchannels on or off.

Now that I explained the theory the best way I could, let me discuss what’s next for this project. Although I did not test my Arduino to my motor control circuit yet, there’s a glaring problem with the circuit. There is no isolation between the Arduino and the circuits responsible for driving the MOSFETs. In order to achieve this, not only will have to look into optoisolators, but also isolated DC to DC DIP modules. But that’s another post. Another item that I will have to look into is setting up an undervoltage lockout circuit for the circuits driving the MOSFETs gates.  By adding an undervoltage lockout circuit, the motor will not turn on until the right amount of voltage is applied to the MOSFETs.

Anyway, that’s it for me today. If you have a question, comment, or concern, feel free to leave a comment. I will see you guys, next week.


Electronics: Serial Expansion Using 74HC4052


I never thought I would say this, but there will be situations which you need to connect several serial devices using one microcontroller.  There are two options to increase the number of serial devices a microcontroller can handle. The default option is to get a microcontroller which has more than one USART port. The second option is to use 74HC4052, a multiplexer/de-multiplexer specifically designed to handle serial communications. In fact, it was the same chip I used in last Wednesday’s mini project post.

What is a multiplexer/demultiplexer?


Let’s start off by talking about what’s a multiplexer. A multiplexer is a sequential circuit designed to accept  multiple inputs, but output the data from one of those inputs based on the input selected. This type of sequential circuit is used all of the time in building the underlying architecture for processors.  A demultiplexer is the opposite of a multiplexer. A demultiplexer is designed to take in one input, and output it to one of the several output pins based on the output selected.  As you can tell by now, the 74HC4052 is a special type of IC that can act as a multiplexer or a demultiplexer depending on the inputs and outputs.

Pinout Explanation


1Z( Pin 13) / 2Z (Pin 3): These pins are the input/output pins of the chip. These are the pins which you’ll want to connect TX or RX of the microcontroller you want to use.
Enable (Pin 6): This is responsible for turning on or off the chip. To turn on the chip, simply connect this pin to ground (0V) and to connect VCC to your positive supply, and GND to 0V.
S0 (Pin 10)/ S1 (Pin 9): These pins are responsible for choosing the input/output pin you wish to use. I’ll explain the purpose of these pins later on.
1Y0(Pin 12)/1Y1(Pin 14)/1Y2 ( Pin 15)/1Y3 (Pin 13): These are the input/output pins to be connected to the 1Z pin. For example, if I connected my microcontroller’s TX pin to 1Z, then I need to connect the RX of my serial device(s) to either one of my 1Yn pins.
2Y0(Pin 1)/2Y1(Pin 5)/2Y2 ( Pin 2)/2Y3 (Pin 4): Same thing as the 1Yn pins, except for the 2Z pin. For example, if I connected my microcontroller’s RX pin to 2Z, then I need to connect the TX of my serial device(s) to either one of my 2Yn pins.
VCC (Pin 16): This is the positive power for the chip.
GND ( Pin 8):  This is where you plugged in 0V.

Method of Operation

So how do you use the device?  The 1Z can be connected to 1Y0, 1Y1, 1Y2, and 1Y3 pins and 2Z can be connected to 2Y0, 2Y1, 2Y2, and 2Y3. The S0, and S1 pins specify which Y pin is connected to its respective Z pin. For example, if we want to connect 1Y0 to 1Z, we connect S0 and S1 to ground.  However, S0 and S1 cannot specify which Z pin is used.  In other words, if we connect S0 and S1 to ground, not only will 1Y0 is connected to 1Z, but 2Y0 will be connected to 2Z. I included the truth table from the 74HC4052 datasheet to show how S0 and S1 affect which port is connected.


Default Wiring Diagram

Default Circuit

The figure above shows an example schematic of the 74HC4052.

If you guys have anymore concerns, or suggestions, please feel free to post a comment!


Tutorials: USART Communication For PIC18 Microcontroller

In my last post, I mentioned two awesome devices I’ve been messing around with lately. The cool thing about those devices is that it only needed one actual pin from the PIC microcontroller to properly work. This pin is one of the pins needed to achieve proper USART communication. Today’s tutorial will serve as a guide in order to achieve proper USART communication. Although I mentioned that USART is used to communicate with the devices I mentioned in the last post, today’s focus will be on achieving communication between PIC18F2550 and the computer using USART.

USART (Universal Synchronous Asynchronous Receiver Transmitter)/ UART (Universal Asynchronous Receiver Transmitter) requires only two pins from any microcontroller to send and receive serial data: TX and RX. You can properly guess that TX is the pin which the microcontroller data is transmitted through, and RX is responsible for data received by the microcontroller. The figure below shows the TX and RX pins on the PIC18F2550.
Keep in mind; we need one more device to have the PIC18F2550 communicate with the computer. If you have an old computer, then you could use a MAX232 and connect it directly to the serial port of that computer. For this tutorial, we’re going to use a laptop to talk to the PIC. In order to do this, we’re going to use a FTDI to USB board from Sparkfun. We’re just going to use 4 pins of the FTDI to USB board: VCC, GND, TX and RX. Look at the figure below to learn how to set up the circuit. Please note that JP2 is connected to the PICKIT3.
Now, create a new project in MPLab X, create a new C file, and code and paste the following code. If you forgot how to create a project in MPlab X, visit my tutorial on starting with PIC18 microcontrollers.

#include <p18f4553.h>
#include <delays.h>
#include <portb.h>
#include <usart.h>
#include <stdio.h>
#include <stdlib.h>

/*	PIC Configuratings */
#pragma config OSC = HS
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config PWRT = ON
#pragma config DEBUG= OFF

/* UART Global variables */
char message;						//	Used for receiving commands from the computer

void main(void)
	//	Set all of PORTC as outputs. TX and RX must be set as outputs first
	//	Configure UART

So open a Serial Terminal program. For this tutorial, I will use the Arduino IDE. Open the serial monitor in the Arduino IDE and set the baudrate to 115200. Finally, type a single character and hit send. You should see the same character you entered appear in the window.
Important! Please Read!

Make sure you enter the right baudrate. If you do not enter the correct baudrate, you will lose data. The figure below shows what happens if we set the serial program to 9600 baud rate even though the PIC is set to a baud rate of 115200.

But how do you know if you set the USART to the right baud rate? Let’s look at the following piece of code.


As you can tell by the name, this is responsible for setting up the USART on the PIC. We’re going to look at the last two parameters of this command. The last two parameters correspond to the baudrate of the USART. USART_BRGH_HIGH sets the USART to a high baudrate, but we can set it to a low baudrate by replacing USART_BRGH_HIGH with USART_BRGH_LOW. The final parameter is a spbrg value. Although there are a set of equations you can use to find this value, as long as you’re using a 1Mhz, 2Mhz, 4Mhz, 10Mhz, 20Mhz, or 40Mhz crystal, you can find the SPBRG value in the datasheet. The figure below shows where we can find the spbrg value.
Well, I hope this helped you guys! If you have any questions, or comments, please feel free to post a comment!


Mini Projects: 160×128 Serial LCD and RFID Fun

download  So lately I’ve been messing around with alot of electronic components lately. One of these beauties is a 160×120 LCD screen. I will admit, they seemed a little daunting at first, but I was fairly surprised how easy it is using these LCD screens.  From what I’ve seen thus far, special commands are executed by sending the hex value 0x7C followed by the proper command. For example, to reset the display, I just need to send 0x7C then 0x00. Of course, to add text to the display, just send an ASCII message to the display. I did not do anything with boxes or lines yet, but will be part of my agenda.

598439_4372418500902_1096039390_nThe last new item I used this week was a RFID ID-120 reader. Like the 160×120 display, it’s controlled via serial. Apparently, this item beauty was shown in Blidr, and the pseudo code for reading the RFID tag was very simple.  In fact, I re-wrote the code to be used with the PIC18F4553, which I will post a tutorial on how to use it before I go back to RPI.

181806_4372421540978_720517165_nThe picture above shows the tag of one of the RFID’s after I ran my RFID reader code on the PIC18F4553. It’s a little slow reading the tag at times, but I find it very reliable.  Well, that’s it for me this week! See you guys on Monday….o wait. The world is gonna end today. Well, it’s nice knowing you guys!





Tutorials: Beginner’s Guide To PIC18 Microcontrollers


Starting today, I will focus on tutorials for  Microchip’s PIC18F series microcontrollers. Why am I shifting my focus from Atmega’s to PIC18F microcontrollers? As I stated in the first post of the N64 emulator controller, which is now Pygames Controller, I spent a semester at RPI learning how to use these microcontrollers and completely forgot how to use Atmegas. Not to mention, a lot of PIC microcontrollers are used for more commercial applications than Atmegas. If I remember correctly, Atmegas are mostly used for automotive applications while PICs are used for more commercial devices (e.g. medical devices). But enough about that! Let’s talk about how to start your first PIC18 microcontroller project.

Necessary Parts

  1. 1x PIC18F4553
  2. 2x 22pf capacitors
  3. 1 20Mhz crystal
  4. 1 PICKIT 3 programmer
    1. It’s highly recommended that you read this user guide for the programmer.
    2. Lots of male headers
    3. 1x Breadboard
    4. Lots of wire
    5. 1x 330ohm resistor
    6. 1x LED (any color)
    7. 1x 10k resistor

Here’s the schematic of the circuit. Although the picture shows a PIC18F4455, they have the same pinout


Necessary Software

  1. MPlab X
  2. C18 Complier

Under the C18 Complier link, select MPlab C for PIC18.So once you guys install the necessary software, follow the next steps for setting up your project with MPlab X. First select file->New Project. Select Standalone project and hit next.


Type in “PIC18F4553” under Devices drop in menu. Hit next.

Select PICKit3 under tools. Press next.


Select C18 as your complier. Hit next.


Now we have create a project name and directory. Normally the project location and folder will be placed under my documents. Before this tutorial, I set the project location under my PIC folder. Remember to select “Set as main project.” This will save you the frustration later on. Finally hit finish.


Now we have to create a main file. Right click on Source files and select New-> C Main file. Type in main.c and hit finish.



Finally copy and paste this code into your main.c

#include &lt;p18f4553.h&gt;
#include &lt;delays.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

/*	PIC Configuratings */
#pragma config FOSC = HS
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config LVP = OFF
#pragma config PWRT = ON
#pragma config DEBUG= OFF

void main(void)


Now we’re going to build and program our mcu. First select build. You should receive a confirmation that the project was built successfully.


Once it finishes building, hit the program button.


Congrats! Your LED is flashing at 10hz!

Here how the code works. Out al of the #pragma in the code, pay close attention to #pragma config FOSC =HS. This tells the PIC microcontroller to accept the external cystal we connect. Please note that if we were using the 28pin PIC18 series microcontroller, this would most likely be changed to #pragma config OSC =HS.

Now for the code. Whenever we want to set a particular pin as an output, we have to access the TRISx, where the x stands for the letter of the port we want (in this case, TRISC for PORTC), and write a 0 to that pin. Thus we write TRISCbits.RC0=0 to set PORTC0 as an output. Finally, to either turn on or turn off this particular pin, we just have to write a 0 (off) or 1 (on)  to PORTC. Thus PORTCbits.RC0=0 is setting PORTC0 off.

Finally, the rest of the code is just flashing the LED on and off every 100ms. The while(1) is there to make sure it runs forever.We, that’s all I got for you guys today! Thank you guys for reading! If you have any comments or suggestions, please leave a comment!