Archive

Archive for the ‘electronics’ Category

Using TMP100 temperature sensor with your PIC – PR5

January 31st, 2012 No comments

In this post I will describe how you can connect the TMP100 temperature sensor from TI to your PIC as well as receive temperature data. The sensor I am using is a generous sample from TI. Compared to the DS18S20 that I used before, this sensor is much faster, it takes 40ms to take a measurement with 0.5 degrees accuracy. The communication protocol is I2C. It could be a bit difficult connect it to your circuit since it is using a SOT-23-6 package.

For this project, I will be using my PIC prototyping board which carries a 18F4520. But you can pretty much use the C18 code in this post, with any PIC having a hardware I2C module.

Package problems!

Because SOT-23-6 is so small the first thing I needed was to create an adapter to make TMP100 compatible with my breadboard. This was a perfect excuse for improving my CNC skills :) . So I created an adapter in EAGLE, cut it out using the CNC and then solder the sensor and 6 pins. The sensor is now breadboard ready!

The TMP100 adapter

 Connection

The connection is really simple. Add two pull-up resistors to the SDA and SDL lines. I used 10kOhm. The datasheet also suggests an optional capacitor on the supply.

TMP100 pinout

 

TMP100 Schematic

As you can see from the schematic there are two pins called ADD1 and ADD0. Those pins determine the I2C address of the sensor. You can find more details in the datasheet. I connected those two lines to GND therefore the address of the sensor I am using is 0×90. That’s all on the hardware side.

TMP100 – Point Register

I2c is the language this sensor talks :) . So we need to use your PICs I2C hardware capabilities. Initialize your communications using

OpenI2C(MASTER,SLEW_OFF);

This sensor has a Point Register (PR)which (guess what!) points to the address of the register you want  to read or write :)  Before doing anything else we should point PR to the temperature register. To do that we have to initiate an I2C communication, send the address of the sensor and tell that sensor whether we like to write or read from it. This is done using a single byte. You see, the address is 7-bits starting from the MSB and bit 0 indicates whether is read or write operation (0=Write 1=Read). Let’s do an example. Our sensor’s address is 0×90. We wish to read something from the sensor so the byte should be 0×91. If we wish to write something to the sensors it should be 0×90. That’s it.

Therefore to write to point PR to the temperature register we should issue the following

StartI2C();
WriteI2C(0x90); // Call the sensor with WRITE
WriteI2C(0x00); // Write Temp reg to point register;
StopI2C();

Notice the 0×00? That is the address of the temperature register. The sensor is now ready to give us some temperatures.

TMP100 – Read that temperature

To read the temperature off the sensor, we need to call it using its address and READ (what we said above, remember?) and the sensor will transmit two bytes of data back. We read that using the appropriate I2C commands shown below. We have to acknowledge the reception of the bytes to let TMP100 know that we are ready for the next byte. Temperature is read as follows

StartI2C();
WriteI2C(0x91);
first_byte = ReadI2C();
AckI2C();
second_byte = ReadI2C();
StopI2C();

The temperature is made out of two bytes. If you don’t care about getting any decimals you can just use the first byte. The 4 most significant bits of the second byte contain information on the decimal value of the temperature.

TMP100 – C18 Library

I made a really simple library for tmp100 in C18. Just include the tmp100.h file to your project and make sure you initiate the I2C (the OpenI2C() command shown in this post) before calling any functions.

 

OK that is pretty much. You should be able to get some measurements out of that little sensor. If you need further help take a look at the example below

#pragma config OSC = HSPLL
#pragma config WDT = OFF
#pragma config PWRT = ON
#pragma config LVP = OFF
#pragma config PBADEN = OFF
 
#include <p18cxxx.h>
#include <i2c.h>
#include <usart.h>
#include <delays.h>
#include <p18f4520.h>
#include <stdio.h>
#include "tmp100.h"
 
void main(void) {
 
    unsigned int raw_tmpr;
    char str_tmpr[8];
 
    OpenUSART(USART_TX_INT_OFF &
              USART_RX_INT_OFF &
              USART_ASYNCH_MODE &
              USART_EIGHT_BIT &
              USART_CONT_RX &
              USART_BRGH_HIGH,
              21);
 
    Delay10KTCYx(250);
 
    OpenI2C(MASTER,SLEW_OFF);   // Initialize I2C module
    tm_setconf(0x60);   // Set sensor to full sensitivity
 
    while(1)
    {
        Delay10KTCYx(500);
        raw_tmpr = tm_gettemp();    // Get 2 bytes of temperature
        tm_tostr(raw_tmpr,str_tmpr);    // Convert the temperature to text
        printf("Temperature is %s\r",str_tmpr); // And output through USART
    }
    return;
}

I connected the USART TX/RX line using my CP2102 and used the cutecom program on Ubuntu to read the output on my PC. The screenshot below shows the terminal

The terminal on Ubuntu

Incoming search terms:

  • convert tmp100 register to decimal (1)
  • tmp100 pic module (1)

1-Wire (OneWire) C18 library

November 17th, 2011 No comments

So yesterday I wanted to get some temperature measurements from a DS18S20 thermometer to my PIC prototyping board. This thermometer uses the 1-Wire communication protocol so I searched around to find a 1-Wire library for the C18 compiler I am using. Maybe I am wrong but I couldn’t find any. So I created one, hence this post.

I had a post about the 1-Wire protocol a while back so you can read that if you are not familiar with it. To implement this protocol we need to work with precision timing. Ideally this could be written in asm. However, for convenience reasons I wrote this in C. I don’t really mind the minor performance penalty :)

Just to be clear, this is a library for the 1-Wire protocol, not for any of the supported devices. The library contains 3 main functions:

  • 1-Wire Reset
  • 1-Wire Write
  • 1-Wire Read

Using these three operations we can have full communication with any 1-Wire device. Let me demonstrate first and then I will write about how you can use it in your project.

A brief demonstration

To demonstrate this operation, I connected a DS18S20 thermometer and connected the DQ line on my PIC’s Port C Pin 1. The procedure I will follow is:

  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Convert T command (0×44)
  • Wait for 1+ second
  • Issue a Reset pulse and observe the Presence of the thermometer
  • Issue the Skip Rom command (0xCC)
  • Issue the Read Scratchpad command (0xBE)
  • And read the next two bytes which represent the temperature

Lets see the C code I loaded on my board Read more…

Incoming search terms:

  • c18 one wire (5)
  • onewire c18 (4)
  • onewire c c18 (3)
  • pic 1 wire protocol c18 (3)
  • c18 libraries (3)
  • c18 library (3)
  • mcc18 one wire (3)
  • c18 compiler 1 wire (3)
  • OW_write_byte (3)
  • c18 1wire library (2)
Categories: electronics Tags: , ,

Serial Interface Between PIC and PC – PR4

October 4th, 2011 No comments

This one is really useful.

Most of the times you are developing a project, you will need some sort of monitoring or visual output to understand the status of your program. Sure some LEDs blinking are great but some times you need more. This is where the good old serial communication comes in. Through this communication you will be able to send information in the form of data or text, to and from your computer. You can use it as a debugging tool to monitor what is going on in your microcontroller during execution time. Or you can use this communication to send data to the PIC for processing and then receive the result back. I am sure you will appreciate the usefulness of this as soon as you implement it.

And all this happens by sending a sequence of zeros and ones… Read more…

Incoming search terms:

  • cp2102 (13)
  • PIC18F DataRdyUSART (6)
  • max232 connection with 16f877a (4)
  • what do with cp2102 (4)
  • sure cp2102 buy (3)
  • Terminal from Br@y (3)
  • XBee spi (3)
  • CP2102 picaxe (3)
  • pic interface with pc (2)
  • cp2102 PIC (2)
Categories: electronics, projects Tags: , ,

PIC and 5110 Interface with SPI hardware – PR3

September 26th, 2011 No comments

This is the first “official” project I am doing with my PIC prototyping board. This project is about interfacing and using a simple Graphic LCD. So to follow this project you need a PIC to have SPI hardware, in order to communicate with the device. The GLCD (Nokia 5110) I am using is well known in the community and it is a cheap device. I bought it off ebay for about 5 Euros. Read more…

Incoming search terms:

  • interface pic18f con lcd (13)
  • spi gears (6)
  • pcbgcode (5)
  • spi pic (3)
  • spi hardware interface (3)
  • Nokia 5110 pic micro code (3)
  • pic spi hardware (2)
  • pic32 spi (2)
  • pins hardware SPI 3510i lcd -atmega -avr (2)
  • pic18f4550 SPI comunication (2)
Categories: electronics, projects Tags: , , , ,

PIC Prototyping Platform – PR2

September 7th, 2011 No comments

Hey,

In PR1 project, I talked about creating a stable prototyping platform that would save me from the trouble of setting up the microcontroller and all its required components. However, since then, I worked on tidying up this design into a more usable design (I wanted to play around with creating PCB actually :D ). So I designed the board sent it for fabrication and finally put it together. Read more…

Incoming search terms:

  • PIC18F8722 prototype board (4)
  • prototyping platforms (2)
  • prototyping platform with pic (2)
  • prototyping headers (2)
  • pic18 c18 (2)
  • pic18f4520 project (2)
  • bom pr2 (1)
  • project of prototyping of gears (1)
  • pr2 in pic (1)
  • platform pic (1)
Categories: electronics, projects Tags: , ,

Components for the Prototyping board arrived!

September 1st, 2011 2 comments

Hey guys,

A couple of days ago, the components for my new PCB arrived so I was able to test my design. The result was successful! Personally this was a simple board carries a lot of “firsts” for me. To begin with, it was the first time I ever designed a board on EAGLE that became an actual PCB. This might sound stupid but its different to make a design for home production (using chemicals) and a design that includes 2 layers, vias, solder masks, silkscreens, correct drill holes etc. I am not saying its hard, I am just saying its different so there are new things to consider.

Another “first” was the soldering of a TQFP package which as it turns out its not that hard (actually its like magic ;) )! I had to buy some solder paste and a tweezers to make my life easier. I am suggesting to check out Surface Mount Soldering guide if you are interested.

Anyway, for a first attempt, I believe the results are pretty good. I made a simple blinking LED program which works, the power switch and reset button work, so I am assuming the design is OK.

I will make another post soon to include the schematics and stuff if anyone is interested and hopefully start producing some projects on this proto board. Finally here are a couple of pictures of the board:

Looking good!

Dimensions are 5cm x 5cm

Incoming search terms:

  • eagle board to protoboard (1)
  • recent electronics components arrived (1)

Low Cost PCB Fabrication

August 13th, 2011 2 comments

Hey guys. I am really excited today because my first ever PCBs arrived from the fabrication house! I always wanted to have my own PCB printed but I was deterred by the price. So I used other methods such as developing my own board which can get quite messy or just sticking with the traditional prototyping boards. Few weeks back, I read a post from Kenneth, which led me to this fabrication house. They actually offer 10 PCBs maximum sized 5cm*5cm, for only $9.90 and $4 for delivery! This is really really cheap! Read more…

Incoming search terms:

  • iteadstudio pcb (17)
  • low cost pcb fabrication (3)
  • iteadstudio (2)
  • pic18f452 pcb (2)
  • pcb lowcost (2)
  • pcb fabrication (2)
  • low cost pcbs (1)
  • pic prototype pcb (1)
  • low cost pcb (1)
  • pic18f84a simple pcb (1)
Categories: electronics Tags: ,

XBee Dropping Bytes – My Solution

April 29th, 2011 No comments

Hey guys a quick post here.

Since the first time I used XBees (2 years back?) I noticed that they were dropping bytes. This is quite annoying as it disturbs the normal flow of your device. What I did fixed it for good and I never had a single bit dropped from XBees ever again, and let me tell you I sent many thousands bytes so far :)

Anyway, what you need to do is really simple. You need to assign a destination to your transmission. You do that by first  entering the command mode (when using the AT firmware). To do that you need to enter the “command sequence character” three times in a row i.e. for the default settings enter “+++” (without the quotes) to the terminal. The XBee should reply with “OK” and you have a short period of time to enter an AT command. Next you need to send the destination XBee by entering “ATDN<DESTINATION ADDRESS HERE>”. And that’s it :)

Let’s do an example. You have two XBees, one is called BASE and the other one is called HELI. Oh make sure you name your XBees by changing the Node Identifier in the settings. If HELI wants to talk to BASE it will

  1. Enter “+++”
  2. Wait for “OK”
  3. Enter ATDNBASE

Now you can send as much data as you want and you wont loose a byte. This is so simple. Do the opposite i.e. BASE->HELI and you will have a pretty good two way communication.

Let me know if you need any help

Incoming search terms:

  • xbee atdn (7)
  • command sequence character for xbee (2)
  • how to use atdn command of xbee for setting destination address (2)
  • xbee c18 library (2)
  • ATDNコマンド xbee (1)
  • byte dropping xbee (1)
  • c18 xbee library (1)
  • xbee dropping bytes (1)
Categories: electronics Tags:

Total Beginner’s PIC Platform – PR1

April 27th, 2011 No comments

So I was thinking its time to start posting some complete projects. I am starting with some really basic projects to help the people just starting with PICs. However, before doing that we need to have a common platform to develop on, so we don’t need to discuss about it every time. In this first project (see how I codenamed it PR1!) we will create a minimal PIC platform which we will use in future projects. I will list everything you will need to buy to get you started.

As the brains of this platform I am choosing the PIC18F4520 which I believe it is a pretty nice PIC to work with, having enough peripherals, memory and speed for any beginner project. Let’s see the components you will need:

  1. Breadboard – if you don’t have one, you really need to buy one!
  2. PIC18F4520
  3. 10MHz oscillator
  4. 2 x 22pF capacitors
  5. 10kOhm resistor
  6. 7805 Voltage regulator
  7. PICKit 2 (or 3)

Using the above components will allow to build a functional board even though more components are needed to be “perfect” (smoothing capacitors on the regulator, a couple of diodes between the programmer and the supply and more). Of course it would be nice to add a switch, a reset button, LEDs, and the list goes on, but this would increase the cost of the board. Consider this as a quick-and-dirty solution just to get you started. Maybe on a future post we create a more complete board. For now I believe this is a good starting PIC testing board.

Using the schematic below, hook up the board. I am also attaching a photograph of my own testing board for reference. You also need some sort of power. I find it convinient to use the 9V battery holder and connect it either with a 9V battery or a power supply. Feel free to use any kind of power supply as long as it is between 6V and 12V. If you are (somehow) using a 5V supply, take the 7805 regulator out.

After connecting everything it would be a good idea to write a simple program to check the functionality of the board. I have a simple LED blinking program already compiled. So, using your programmer, transfer the HEX file (attached at the end of this post) to your PIC. To test this out you will need an LED and an 1kOhm resistor connected to the A0 pin as shown in the figure. Turn on the PIC and the LED should be blinking every 1 sec. If not then something is wrong :) . But don’t worry. The board is simple enough to figure out where the mistake is and if you have trouble you can always ask me.

So now you have a board to play with :)

Incoming search terms:

  • beginner pic projects (3)
  • pr1 pic (2)
  • pic beginner projects (2)
  • pic beginners projects (2)
  • pic18f4520 projects (2)
  • pic projects for beginners (2)
  • what is pr1 in pic programing (1)
  • platform people picture (1)
  • pic24 project (1)
  • pic platform (1)
Categories: electronics, projects Tags:

Fixed Time Loop in Microcontrollers

March 31st, 2011 No comments

Hey.

Most of the times I am developing a piece of code for my PICs, there is a main loop in the flow. The code repeats it self indefinitely doing its thing and it is only interrupted temporarily by the hardware interrupts of the PIC. Now most of the times a simple while(1) { // code here } will do just fine. However, sometimes your need that loop to start at specific time interval for example every half second. This is pretty useful when somewhere in your maths you need a specific dt. Read more…

Incoming search terms:

  • oscilloscope screen png (1)
  • set_timer0 (1)
  • time loop in interrupt (1)
  • time loops microcontroller (1)
  • timed loop microcontroller (1)
Categories: electronics, programming Tags: