Quantcast
Channel: Clock - Timer Projects - PIC Microcontroller
Viewing all 218 articles
Browse latest View live

Alarm Clock Retrofit using PIC16F877

$
0
0

I had some beef with my (very) old alarm
clock.  It had a radio which was nice to
wake up to, but two problems:

1) I would be in bed and think “Wait, did I
set the alarm?”  I would have to get up,
turn on the light and look at the position
of the tiny black sliding switch.

Alarm Clock

2) When I wake up in the morning and
turn off the alarm, it’s still set to go off
the next morning.  When I started this
project I had a roommate.  I would wake
up 5AM on Monday and take off on a
business trip.  5AM Tuesday it would go
off again.  Too bad for him!

I decided to retrofit it, ripping out the chip that runs the
show, replacing it with a microcontroller I could program
as I liked.  All in all, it was an awful lot of work, but it feels
good to have it work my way.

There’s a second 4-digit display on top that shows the
alarm time.  If this is lit, the alarm is set.  You can tell at a
glance whether it’s set.

Turning it off in the morning turns it off for tomorrow as
well.  I find it a lot easier to think of what time I want to get
up tomorrow as I go to bed, rather than when I wake up.

I added a new 3-way toggle switch on top.  Pulling
it to the right turns on the radio to listen right now.
Clicking it to the left once makes the alarm active
(and the top display goes on), pushing it left again
turns it off.  Two of the switches that I salvaged
from inside I reattached to the left of the display to
set the hours and the minutes.  If the alarm is set,
these buttons change the alarm time, if not, they
set the clock time.

The alarm time increments in steps of 5 minutes,
since I never need to wake up at 6:03.  Another
somewhat unique feature is that there’s no AM or
PM.  This saves me from setting it wrong and it
would only be a problem if I wanted to sleep for
more than 12 hours!

 

For more detail: Alarm Clock Retrofit using PIC16F877

The post Alarm Clock Retrofit using PIC16F877 appeared first on PIC Microcontroller.


Digital Clock using PIC Microcontroller and DS1307 RTC

$
0
0

A Digital Clock can be made easily by using PIC Microcontroller, DS1307 and a 16×2 LCD. I have already posted about Interfacing DS1307 RTC with PIC Microcontroller. The DS1307 RTC can work either in 24-hour mode or 12-hour mode with AM/PM indicator. It automatically adjusts for months fewer than 31 days including leap year compensation up to year 2100.  DS1307 comes with built-in power sensing circuit which senses power failures and automatically switches to back up supply. We can provide a 3V CMOS Battery for that. Communication between PIC Microcontroller and DS1307 takes place through I²C Bus.

Digital Clock using PIC Microcontroller and DS1307 RTCSuggested Readings:

Circuit Diagram – Digital Clock

Note: VDD , VSS of the Pic Microcontroller and VCC , GND of DS1307 are not shown in the circuit diagram. VDD, VCC should be connected to +5V and VSS, GND to OV as marked in the circuit diagram.

To simulate this project in Proteus you may need to connect I2C Debugger. SCL and SDA of I2C Debugger should be connected in parallel to SCL and SDA of DS1307. I2C Debugger can be found where CRO can be found in Proteus.

You can download the MikroC Source Code and Proteus Files etc at the end of this article. Here I explains the Source Code and different functions used in it.

Digital Clock using PIC Microcontroller and DS1307 RTC SchematicThe Three points to be noted while editing or creating program for this project:

  • DS1307 RTC is fully Binary Coded Decimal (BCD) clock/calender. So the data read from DS1307 should be converted to required format according to our needs and data to be written to DS1307 should be in BCD format.
  • Library for Interfacing LCD With PIC Microcontroller of MikroC needs Character or String Data. So data to be displayed in the LCD Screen should be converted to Character.
  • Addition and Subtraction cannot be directly applied on BCD. Here I first convert BCD to Binary. Then addition and subtraction can be simply applied on Binary. Then the Binary is converted back to BCD.

 

For more detail: Digital Clock using PIC Microcontroller and DS1307 RTC

The post Digital Clock using PIC Microcontroller and DS1307 RTC appeared first on PIC Microcontroller.

Making a binary clock using a PIC16F88

$
0
0

You can use a PIC microcontroller and an LED matrix to create a binary clock (or if you prefer you can wire up individual LEDs).

This project uses an LED matrix block as it saves lots of wiring.  So what is it ?

binary clock using a PIC
Its an led clock that displays the time information as binary numbers…

…and it is a good way of learning how to read binary (well up to 9 any way!).

You can represent the numbers 0-9 using 4 binary digits so only four leds are needed for each time digit. There’s a binary-decimal conversion table here.

To display hours, minutes and seconds (2 digits each) you need 6 binary digits in total (depending on whether you use a 24 hour clock the top digit needs only 1 or 2 LEDs).

How to read a binary clock

To show the time 6 digits are needed:

Binary Clock digit defiinition

 

Hours
MSD 0-2
Hours
LSD 0-4
Minutes MSD 0-5
Minutes LSD 0-9
Seconds MSD 0-5
Secondss LSD 0-9

(MSD,LSD Most Significant Digit, Least Significant Digit)


Note: You could use a 5×7 led matrix as only the right hand 4 leds (also only 6 rows) are used in this project.

The black rectangle, in the diagram above, shows which leds you need to look at – the rest are not used in this project.  You read the clock starting from the top and read horizontal row of four LEDs as a binary number. Each LED that is on represents a one and each LED that is off represents a zero. You then use the conversion table to translate it into decimal until you become so good at it that you won’t need the table!

Hardware

This project uses the same hardware as the led matrix project using a 16F88 PIC microcontoller and an LED matrix.  Its worth taking a look there as the same hardware description applies on how to multiplex the display.

I’ll just say here that instead of using 64 output pins only 10 are needed to drive the display.

 

For more detail: Making a binary clock using a PIC16F88

The post Making a binary clock using a PIC16F88 appeared first on PIC Microcontroller.

Digital stopwatch using microcontroller

$
0
0
How much time this event will take to finish?OK, Let’s countdown the time.So a stopwatch is the best solution.Just press the start button to start countdown then stop when the event completed.Now every cellphone has this feature but i was determined to make a digital stopwatch using micro controller as I am very fond of  this type of works.
This project is about to make a digital stopwatch. Whole project is simulated in Proteus 7.
MikroC is used to write the code.
The circuit is easy and we just need
Digital stopwatch using microcontroller
  • PIC16F73(1pc)
  • 16×2 LCD(1pc)
  • Push Button(3pc)
  • 20 MHZ Oscillator(1pc)

Here we use three buttons.

  1. START Button
  2. PAUSE Button
  3. STOP Button

To understand the whole project look at the final output of the project.
Just make the connections as the figure shown.
This project file is compiled in MikroC Pro 5.8.0.

Connection Detail:

  • PIC RB2 —- LCD RS
  • PIC RB3 —- LCD EN
  • PIC RB4—- LCD D4
  • PIC RB5—-LCD D5
  • PIC RB6—-LCD D6
  • PIC RB7—-LCD D7
  • GROUND—-LCD R/W
  • PIC RC0—-START BUTTON
  • PIC RC1—-PAUSE BUTTON
  • PIC RC2—-STOP BUTTON
  • 20 MHZ OSCILLATOR IN XTAL PINS
  • PIC VCC  5V

Digital stopwatch using microcontroller SchematicLoad the HEX file to the pic microcontroller.

Give power to the board and press the buttons to see the output in LCD.
Any Complexity ? Or Facing Problem ?? Just put comment. I shall try to help.
As I have shared the whole project code you can modify the code in MikroC as you need.

 

For more detail: Digital stopwatch using microcontroller 

The post Digital stopwatch using microcontroller appeared first on PIC Microcontroller.

Naked Clock using PIC16F877 Microcontroller

$
0
0

Why have an enclosure?  The enclosure of a clock
doesn’t tell you the time!  So I built this PIC clock with no
part that doesn’t serve an electrical function.  The
hanger is the ground.

The microcontroller is the 40-pin PIC 16F877.  I set it up,
then let it run for a few weeks, saw how far off it got, then
went back into the code to add an extra delay to get the
timing just right.
Naked clock

Lessons Learned:

I originally planned to have this run off a 9 volt battery, but I
found that it would drain the battery in less than 24 hours,
not an ideal clock!  So now it runs off a wall adapter.

There’s a resistor between the LEDs and the ground that is
the hanger.  Since several segments share one resistor, the
brightness of one segment depends on how many of its
neighbors are on.  The seven digit has the biggest problem.
It would have been better to put the resistor between each
pin and LED segment instead.

 

For more detail: Naked Clock using PIC16F877 Microcontroller

The post Naked Clock using PIC16F877 Microcontroller appeared first on PIC Microcontroller.

A RGB LED Matrix Clock

$
0
0

Introduction

In today’s world of rushed schedules, time is something a ton of people are in constant need of keeping track of. A very good method for keeping track of the time is to have a wall clock. But what if you want a clock that’s different from all the others, or something that will stand out and make your friends say “Hey, that’s pretty awesome!” That’s precisely what we set out to make when we undertook this project. Using the PIC32MX250F128B microcontroller, we built a wall clock that is made from a 32×32 LED Matrix. The clock comes with an IR remote that can control a variety of customization options and smaller features such as a stopwatch and alarm. It also has a serial channel that can connect to a PC to update the time to match your PC internet synced time.

This project was completed over a five-week period for the ECE 4760: Designing with Microcontrollers class under Professor Bruce Land.

High Level Design

Overview

Our project runs off of a PIC32MX250F128B microcontroller, which handles all the controls and processing of data for the 32×32 LED Matrix. An Oscillator crystal handles the realtime-keeping component of the clock, and an IR reciever handles the input from our IR Remote Controller. We also have a serial connection to a PC so we can update the time to match the internet-regulated standards that most PCs sync with on a daily basis. All of these components come together to create the LED Matrix Clock we have designed, and we will go into more detail on these below.

Rationale

The idea for this project arose from the growing popularity of home appliances being both programmable and connected to the internet. As technology continues to evolve and become cheaper, more and more homes and buildings are incorporating these appliances that can be controlled through the internet, such as the Nest home heating unit and the Phillips Hue lighting system. We believe that this LED clock would be a great addition to a home that utilizes internet connected components. The our display could provide a central status hub that reports the status of various other components in the house as well add to a modern technological atmosphere.

While we did not accomplish the ambitious goal of creating an internet connected centralized display this semester, we did build a self contained and novel device that works as functional clock. This is the first step in creating a more useful display and as will be discussed later on, hopefully the start of an on going project to add upon this clock that will make it go above and beyond the exciting wall clock.

Standards

Our project does not (as of this time) utilize RF communications or other regulated technologies, and therefore we could not find any pertinent standards to reference. We had anticipated finding standards for infrared remote technology but again, while we did find some standards used by various companies, we did not find any widely adopted standards that would be relevant to include with our project.

Relation to Existing Works

This project can and should be seen as very similar to the many LED Matrix displays. There are tons of creative LED Matrix projects of every kind, however, they are almost all done by hobbyists who either do not actively share any code or are completely opensource. Additionally, the vast majority of these hobbyist projects are done using the Arduino or more powerful systems such as a Raspberry Pi or FPGA, the former being very easy to work with and the later being highly performant for larger displays. At the onset of this project we were unable to find any documented projects using both the PIC32 architecture and a 32×32 RGB LED matrix. Everything we have done, excluding the resources referred to below, has been our own invention, inspired by our own interests and our peers’ ideas.

Hardware and Software Trade-offs

Our project relies heavily on software. One major trade-off we had to decided between hardware and software was for the time keeping. We ran into an issue with the Pic32 RTCC module running too fast. It ended up being an issue of capacitance affecting the crystal (an affect of working on a breadboard we suspect). However, at that time we decided to try and use the UART serial interface to power all time keeping ability. In other words, a computer with a serial connection would send time updates over UART every second (or faster) in order for our system to update the display. We discovered that this is possible (we managed to get very good accuracy using this method). In the end though, once we fix the oscillator issue, we decided to use the pic32’s RTCC unit instead. The benefits of this being that the system is now less coupled to a serial tether to a computer. Relying on software on the computer to send the time updates meant that if you turned off your computer, software on either the computer or the microcontroller failed, or a serial device lost connection the clock would stop telling time. Meanwhile, the computer clock is typically internet synced and always accurate but the major reliability issues spurred us to pick the best of both worlds where the RTCC is used to keep time but it confirms the time with the computer periodically if a serial connection is present.

High Level Block Diagram

The block diagram below shows how the various components of our project interact with each other on the highest level. The Python Application handles the syncronization of time with the PC’s system time, but all data from the PC is eventually fed back to the PIC32 to be processed.

User Interface

The user interface for our project consisted of an Adafruit Mini IR Remote, which would control the clock’s various functions based upon which button was pressed. Additionally, the serial interface would allow for the time to be manually set via a UART console. As the project stands now, the IR remote controls the toggling between the Digital and Analog views of the clock as well as between each of the various test images seen in the Results section below. Simply press the Left and Right arrow keys to change between the different views.

Ideally, we would have used the IR Remote to control a menu interface that would come up on the LED Matrix, but due to time constraints, this feature was not implemented. However, it would be very simple to add on to the current control system just by adding in additional command handlers for the various buttons on the remote.

Hardware

Hardware Overview

The hardware for this project included several components. The most notable component is the Adafruit 32×32 RGB LED matrix display. The construction of our final product revolved around getting all the hardware bundled together on the back of the matrix so that it could be hung on a wall or stood up on a surface. In addition to the matrix and its control components (displayed in the image below) we also used two IR remote units for remote control.

Back side of the matrix clock showing the various highlighted hardware components. Green The Microstick II housing the PIC32 microprocessor. Red The solderboard circuit for the realtime clock oscillator. Magenta The connection for the RGB LED matrix display. Yellow The serial to usb adaptor. Cyan The IR receiver mounted to be visible from the front of the matrix.

The circuitry can be broken down into each component used below. The schematics for the circuits can be found in the Schematics Appendex section. All Pin connections to the MCU are specified here in the table below.

Device Pin(s) MCU Pin(s) Function
IR Reciever SIGNAL OUT 13 Input Capture 1
32.768 kHz Oscillator SIGNAL OUT 11 SOSCI
LED Matrix R1, G1, B1 (color data) 4-6 IO
LED Matrix R2, G2, B2 (color data) 16-18 IO
LED Matrix CLK (data clock) 2 IO
LED Matrix LAT (data latch) 3 IO
LED Matrix OE (output enable) 3 IO
LED Matrix A, B, C, D (row select) 7, 14, 25, 26 IO
UART TX 22 UART 2 Recieve
UART RX 21 UART 2 Transmit

RGB Matrix

The RGB LED Matrix has a five part wire interface:

  • 6 wire channel for writing two RGB LED values at a time – you can only write on or off for each of the red, green, blue values at each pixel
  • 4 wire row selection – only two rows are on at a time these bits select which rows, the binary value 0 would turn on 0 and 16, 1 would be 1 and 17, etc.
  • A clock signal – indicates that the color values should be latched for the next pixel
  • A latch signal – indicates that we are done writing the selected row and the values should be latched and displayed
  • A output enable signal – indicates that the currently selected row should be on

The pins these connect to on the PIC32 are listed in the table above.

IR Sensor

The IR circuit was relatively simple, requiring only the TSOP38238 IR Receiver Sensor and a 330 Ohm resistor to protect the PIC32 in case of a surge. The IR reciever simply outputs pulse signals on Pin 13, that we pick up in software as described in the Software section below. Additionally, we made it compatable with the Adafruit Mini IR Remote as well as a standard Apple Slideshow Remote.

Having two remotes available to us allowed for some interesting ideas for some two-player games to be made, but we didn’t have enough time nor resources to implement this. However, it was great for debugging purposes to have one for each group member!

Serial Connection

The serial to usb connector we used was the Sparkfun FTDI Basic Breakout. We use this chip due to its compact size and separation from a USB cable so that we can use the clock without a serial tether and not have to manage the cable. The TX/RX is connected to the PIC32 microcontroller on pins 22 and 21, respectively with the appropriate PPS configuration selected on the microcontroller.

External Oscillator

The circuit for the External Oscillator manages the Real-Time clock for timekeeping whenever a connection to the PC is not present. This circuit was graciously donated to us by our classmate Udit Gupta. In short, it creates a 1 second pulse signal, which we use as a clock to handle our second-counting via the input on Pin 11.

Software

Overview

The software is the largest part of our project and is almost more of a deliverable than the device itself. We spent a large amount of time creating a standalone library for the LED Matrix display as well as making the project as well broken into logical components as possible. The idea is that anyone can fork our GitHub Repository and easily start customizing the system as they see fit. Towards that goal it was heavy priority to make the project as clean as possible and modular so that in order to changing the use of any component (display being drawn, serial use, rtcc use, IR input, or other) is very simple.

The software breaks up into the following components: LED Matrix Control Library, IR Signal Decoding/Handling, Realtime Clock and Calendar, Serial Interface with PC, and the Python Time-Sync Application. Each part of the software works in unision with each other in an effiecent manner.

Controlling the Matrix

The most challenging part of this project was developing the control library for the Adafruit 32×32 RGB LED matrix. The matrix itself does not come with any datasheets or product guides indicating how to control it. Fortunately, there are several helpful guides for how to use this matrix with the Arduino from Sparkfun and Adafruit as well as a description of the findings of what was found when the hardware was reverse engineered on this page. Additionally, there is an Arduino library written for this matrix. Even with all of these resources it was a challenge to get the display working well.

Matrix Display Library

The first step in porting the Adafruit Arduino library for the PIC32 was figuring out exactly what the library does to drive the display. We did this by hooking up and Arduino an playing with the scope to see what the Arduino was outputting to the matrix. Thankfully the library also includes helpful comments to aid in understanding the reasoning behind much of the code. This is vitally necessary since much of the code is highly optimized in order for the many matrix control wires to be output at a fast enough rate to achieve acceptable visual quality and reduced CPU usage. In the code base this is all part of rgb_matrix.c/h.

Here I will give a brief overview of the LED Matrix control interface and the control library. Better documentation can likely be found at the resources above focused on this topic. Using the wires specified in the hardware section if you wanted to write data to display colors on only two rows of leds (0 and 16) here would be steps:

  1. Set the color channels for the colors you want for the first pixel (column) 0 (so channel one would be the pixel (0,0) and channel two would set pixel (0,16).
  2. Set the clock signal momentarily then clear, latching that color values.
  3. Repeat 1 & 2 for each column from 0 to 31.
  4. Set the latch signal and the output enable high. This will latch the new RGB values to the led controllers and disable the output.
  5. Clear the latch and the output. This will re-enable the output with the new color values displayed.

In order to get a wider color range (12 bit in this case) and display flicker free frames, the process of writing values to the matrix must be done on an accurate schedule as fast as possible. This means interrupts and a timer must be used to drive the display. In order to get 12-bit color from just setting LEDs on or off we use Binary Code Modulation. So since we are doing the entire matrix update in an interrupt to achieve precise timing for binary coded modulation this means we have to be as quick as possible so that the CPU is not always updating the matrix and has time for other tasks such as actually drawing what to display. So to accomplish a very fast ISR there are some tricks that are used. The first is arranging the matrix buffer so that we can read a memory value and immediately write it to an output port without having to manipulate bits first. The second is to make use of the SET/CLEAR/TOGGLE registers for all of the PIC32 control registers which allow us to modify bits in ports without first reading them to maintain the other bit values. Unfortunately, this means there is some inflexibility in the control library such the control pins are mapped to indices in the matrix buffer and with the current scheme you can only use the pins that are setup for it. In further iterations, macros might be used in order to allow some flexibility in the pins chosen for the matrix color control Finally, we ensure that loop unrolling and optimizations are on so that the loops to write to the array are as efficient as possible and this was verified in disassembly. More about the actual timing considerations is discussed in the results section.

With an ISR to write the values stored in a matrix buffer, we can now write values to this buffer and the matrix will display those values stored in the buffer. But since this buffer is being read very fast by the ISR and might not be updated quickly by the main program, you will actually see individual pixels change on the display as they are written by software. This affect is undesirable and to remedy it we use two display buffers. One called the back buffer and one called the forward buffer. We always write to the back buffer and read the current pixels to display from the forward buffer. When we want to update the image, we set a flag that is read by the ISR after finishing drawing the full matrix. The ISR swaps the buffers by simply swapping the pointers to them so it now begins drawing the updated buffer. This means that animations can be very smooth.

Matrix Graphics Library

The matrix display library only gives a few functions to write to the matrix, drawPixel and fillScreen. While powerful there is many things that we want to be standard and not have to think about as a programmer using the LED matrix display. Thankfully, there was also a library providing this for the Arduino and since these functions are more high level they were much easier to port over. Additionally, the ECE4760 TFT display library is actually another port of the Adafruit graphics library to standard C and the PIC32. Therefore after cleaning it up and adding a few additional features we were able to use this library to draw lines, shapes, and text to the display with easy to use functions.

One of our additions to the graphic library was a new font class. We needed a smaller font in order to fit more information on the screen. Therefore, we found an opensource 3×5 font class and added it to the library. This required converting a BDF font file into a C data definition to be used by the microcontroller. To accomplish this we wrote a python script to take in the font definition file, parse it, and write out the hex code values that can be used as a C array definition the bitmap pixels to draw for each character. Additionally, we generalized the printing functionality such that adding new fonts will not be so difficult.

Matrix Library Demos

In addition to creating the drawing libraries, we also ported and added some of the matrix display tests. As mentioned we wanted to have a standalone library. Part of that is having tests to bootstrap any user of the library. The Adafruit tests we ported test shape drawing, color spectrum, and text. We also added some of our own to test rendering images and colorlevels.

Clock Graphics

Since we are building a wall clock system, we need to have the clock faces to display. We added a clock graphics library. This is essentially just a collection of functions that were used to create the two clock faces (digital and analog) we have created during this project but we fully intended to make it easy to swap and tune the clock faces to be customizable.

Handling IR Signals

To get the remote control working with our project, the idea was to be able to decode pulses sent from the remote, via an IR Receiver that would translate the signal into a digital signal. This digital signal would then be fed into the Microcontroller and decoded accordingly. Fortunately for us, the TSOP38238 IR Receiver Sensor came with a built-in differential OP-Amp, and so it would output the square pulses for us from the beginning. It was also tuned to 38 KHz, which was what our remote transmitted at.

The Adafruit Mini Remote Control that we used uses the NEC IR encoding type for transferring the data of which button was pressed. The protocol is relatively straightforward and is explained with stellar detail over at this website.

The difficult part for us, was figuring out the optimal way of decoding these incoming pulses on the Microcontroller in a way that wouldn’t interfere with the large CPU demand of the LED Matrix code. Adafruit graciously included an Arduino tutorial on how they decoded their inputs here. However, this tutorial wasn’t A) optimized for our PIC32, and B) ran the entire code within a loop that would interfere with our LED Matrix code.

To this end, we decided to utilize the same ideas we used in the Lab 1 Capacitance Meter. We would make an ISR that would trigger pulse captures, and then when we were certain that an entire pulse was captured, we would decode it. To do this, we had to utilize an Input Capture on RB13 of the PIC32. The setup for this was just as it was in Lab 1, except we trigger the timer capture on every single edge (rising and falling), because for the initialization pulse, we need both the high and the low widths. Once I had captured all the pulse times, I would then store them in an array for decoding. The following image is from the beginning stages of my work with this. Basically, the values you see in the column marked “LOW” are the timer counts for when the signal pulse was low, “HIGH” when it was high. I had set the timer with a prescalar of 64 on a 40 MHz clock, so each count corresponds to about 1.6e-6 seconds. This is the raw timer counts data, and after messing around with it for a while, I determined the following threshold values for various pulses:

This test program shows all the timer counts for each pulse. The red numbers are the decoded values from each pulse based on the values below.
  • Initialization Pulse: HIGH 5550 – 5850 counts followed by LOW 2650 – 2950 counts
  • Repeat Pulse: HIGH 5550 – 5850 counts followed by LOW 1250 – 1550 counts
  • Logical 0 Pulse: After Initialization Pulse, LOW 200 – 500 counts
  • Logical 1 Pulse: After Initialization Pulse, LOW 900 – 1200 counts

These thresholds are much higher than probably what is needed, but it helps to allow for a large variation in the case of signal interference, especially whenever you use the remote from a distance.

The red numbers are the decoded versions of the pulses to the right. The 52 corresponds to the Initialization Pulse. There was an anomaly with our remote in which the logical inverse of our address (0x00) was always (0xFC) instead of (0xFF). We worked around this by just ignoring the logical inverse portions of our signal in the final decoding stage. Once everything was decoded into 1s and 0s, it was easy to then just check that the incoming address was 0x00, and translate the 8-bit opcode to a string.

Realtime Clock and Calendar

The realtime clock and calender was very easy to setup after reading through the PIC32 documentation and examples online. Using the plib.h functions all that needs to be done is call the corresponding RTCCOpen() function and the RTCC should initialize and be ready to provide the time. Now, this is using a very trivial setup, however. A better application would use a drift correction algorithm to calculate the errors of the 32.768KHz oscillator that drives the realtime clock. This will be discussed further in the results section.

In addition to simply enabling and reading the values directly from the RTCC, we added a set of date/time functions in datetime.c to ease using the dates and converting between the Binary Coded Decimal values provided by the hardware RTCC. This also includes helpers to convert to strings to display dates.

Serial Interface

The serial interface we added to communicate with and set the time on the PIC32 is very simple. We use the Cornell Protothreads UART functions to read and write from the UART in a nice threaded protocol. We did find, however, that using the PT library to send serial data was a bit cumbersome and as such added some very convenient wrapper macros to simplify the sending of data using the PT library (these are in the serial extensions file, serial_ext.h). The actual communication interface over serial consists of four messages. The PIC32 will send a “gtd” message (get time date) to the computer when it needs a time update. If the computer is connected and listening, it should respond with a time and then a date message. The time message just consists of the format:

“t <hours>:<minutes>:<seconds>”

This corresponds to the human readable time that the PIC32 should update to. The date is the same idea but the message format is:

“d <month>/<day of month>/<year>-<day of week>”

The last message that can be sent is a “BAD CMD” from the PIC32 to the computer. This indicates that a message was received that did not match either the time or date pattern. Each of these messages must be terminated by a carriage return as a end delimiter. Without a carriage return the PIC32 will read until its buffer is full and then parse the input which will result in an invalid if the max buffer does not match the specified patterns. To parse the patterns a simple sscanf is used with an appropriate format string.

Python Time-Sync Application

In addition to the code on the PIC32, we also had to have an application running on the computer to receive and respond to time/date update requests from the MCU. We wrote a simple application in Python 3.5 using PySerial as the serial communication library. The appication simply waits reading the serial input until it gets a “gtd” message at which point it sends both the time and date. We found that we had to manually add delays to the serial write methods in order to avoid overflowing the PIC32s input buffer. We found that typically unthrottled writes of more than 8 characters resulted in the PIC32 UART receive interface locking up. The ensure that this does not occur under normal operation, we modified the PT UART library to check the UART overrun bit and clear it to restart the UART receiving. We suspect that we were encountering this error more that typically because our large amount of time spent in the matrix display interrupt caused the receive fifo buffer to not get read as often as it would typically.

 

 

 

 

 

 

 

Matrix Display

The matrix display results were excellent. Due to the PIC32’s faster clock speed (running everything at 40MHz so room to improve further) and memory footprint, we were able to successfully control the matrix at a refresh rate near 450Hz using roughly 30% CPU. This is the CPU time that is required to just update the matrix display, it does not include any time to actually draw anything to be displayed. In order to measure the time in the ISR we added test code to toggle a bit when entering and exiting the ISR then measured the times on an oscilloscope. Since there are four different control flow paths and different spacings of the ISR we measured the ISR for four interrupts and the delay between. The whole period (which corresponds to drawing a single row) takes 137 microseconds and in that time we are in the ISR for 11.6 + 8.8 + 8.0 + 8.0 = 36.4 microseconds. So therefore we are spending 36.4 / 137 = 26.6% of CPU time handling the ISR for the matrix update. Now we have to do one of these updates for each row (16 rows since we write out two rows at a time) so in order draw the entire matrix once it takes 16*137 = 2192 microseconds. This corresponds to a refresh rate of 1/0.002192 = 456Hz. This may seem extremely high since humans it is above the typical frame rate at which humans can notice. However, due to the use of binary coded modulation to get the colors and only two rows of the matrix are lit at a time, this refresh rate is necessary to make the display appear non flickery and as smooth as it is.

The display looks excellent visually for all colors and animations except on scenario. There is some issue with the red color input for the upper half of the matrix. When displaying bright red colors (high amount of red) in the upper half, we end of getting flickering of the red LEDs in the middle of the matrix. Experimenting with swapping ports and with other colors revealed that this is only an issue for the color red and only for the top half of the matrix. We hypothesize that it may be a voltage issue since the matrix is typically uses a logic level of 5V instead of the 3.3V of the PIC32, since we just discoved this issue recently we unfortunately, have not had the opportunity to swap in a logic level converter to see if it makes a difference but that is the next step.

IR Control

The IR Controllers worked fantastically as controls for the Matrix. Although we didn’t get the menu interface in as we intended to, toggling from one view to another was as simple as a single button press.

Using both remotes worked smoothly as expected as well. There were some observed differences between the two remotes that made us consider using one over the other in the future as well. The main observation was that the Adafruit Mini IR Remote was much weaker in its range than the Apple Remote. The Adafruit could only be detected at ranges less than about 5 meters, while the Apple Remote could work at ranges as long as the lab (which is at least 25 meters). However, the Apple Remote encountered some issues with interference with a classmate’s MacBook laptop. Whenever buttons on the Apple Remote were pressed, occassionally PowerPoint would open on their computer. We knew that using the Apple Remote had the potential to interface with Apple computers, but usually a “pairing” in neccessary before the laptop will recognize this. The Adafruit Mini Remote did not have any interference issues with any other devices within the lab. Considering these factors, we decided it might be a better idea to only use the Adafruit Remote in the future, as it’s low power and non-associtivity with existing devices give it lower chance of causing interference with other devices.

The signal interference made an important point when considering which remote to use, which is also why our IR Decoding method always checks the signal address. Both of our remotes used address (0x00). To make sure we didn’t decode other group’s IR signals, we only would accept signals that transmitted with this data address as its target.

Serial Interface

The serial interface works wonderfully with the PIC32 after throttling send rates from the computer and checking the error bits. We now only send a character every 2 milliseconds but we only send 11 characters max with the time and 13 characters for the date. This results in a expected delay of about 22 milliseconds minimum for the time (which is more crucial since we are setting a realtime clock). It then may take additional time for the PT library to wake up the serial thread to actually process the message. We found that adding a second to the time before sending to the PIC32 generally improved the accuracy. We believe that determining the average time for the serial thread to process the message would be desirable but might be overkill since we do not require precise timing.

As an aside, before we got the RTCC on the PIC32 operational, we were able to get the serial interface sending precisely timed updates to the PIC32 to maintain the time very well. This of course has drawbacks of being very coupled to the computer and more failure points but is a good fall back mode.

Realtime Clock and Calender

Our realtime clock and calender unit ended up being less accurate than desired. We did not get a chance to do precise measurements in the lab of the accuracy but we did a extrinsic test of the clock being used for a 48 hour period. For the first, 24 hours the clock started at perfectly in sync with computer time (truth value in this experiment) and was detached from the computer (no serial communication to update). We found that the time was approximately 14 seconds fast after that 24 hour period. This is a huge error of over a minute and half a week and unacceptable for the device we wanted to create. However, the second half the of the test consisted of 24 with the serial tether connected to a PC. For each checkup we made the time was perfectly in sync (as measured by the human eye). So in this case we cannot rely on the real time clock unit for any period of time greater than an hour (half a second loss estimate). We believe this error is caused by issues of packing the oscillator along with the other higher frequency control wires all in the back of the matrix unit, possibly causing interfere and disrupting the timing but without doing the proper testing with a oscilloscope it is hard to determine.

Conclusions

Summary

Our project did a lot of what we set out to do, but didn’t meet 100% of our goals. We intended to have a menu interface that would be controllable via the IR remote that could be used to set Alarms as well. Other than that, though, all of our goals were met with excellent results. An entire control library for the 32×32 LED Matrix was written, including fonts, animations, and shape drawing. The time was kept in an accurate manner, it syncs with a PC’s time, and is displayed in both Analog and Digital fashions. The IR Remote can be used to toggle between various images and the two time displays, with no issues at all. In our opinions, the project met almost everything of what we set out to do, with the groundwork set for much expansion in the future. We are very satisfied with the results, and hope to continue working on this project into the future.

Applicable Standards

Our project did not have any standards that applied to it. We personally did not want our IR devices to interfere with others, and so we decided to use the Adafruit Remote over the Apple Remote to nullify this issue.

Intellectual Property Considerations

We do utilize three libraries in our codebase which were written by others. The first is the Cornell protothreading library. Written by Bruce Land, this library contributes by adding a UART interface and threading system (adapted from the protothreads library written by Adam Dunkels). We have also made modifications to this library to suit our appilication. The second library we used is the Adafruit RGB Matrix Panel Library for Arduino. We used this library as a means of testing and reverse engineering the interface for controlling the RGB matrix. Our our control library for the RGB matrix is heavily based on the concepts from the Adafruit library but re-written for the PIC32 architecture. Finally, we also adapted and added to the Adafruit GFX Library for Arduino. We used an already adapted version of this library (adapted by Syed Tahmid Mahbub and can found at his blog). We adapted it further for the matrix as well as adding additional functions as necessary. All of these libraries are open source and have no restrictions on use provided proper referencing.

We also use a bitmap font definition that is available for opensource use under the MIT license which we have included with our project as required.

Ethical Considerations

Throughout the entire period in which our project was performed, future and prior, all members of our team strictly followed the IEEE Code of Ethics. All decisions within the group were made with the safety of all members and welfare of the public put firstmost. No conflicts of interest were encounted during our project. All data and measurements stated on this page are truthful to the best of our knowledge. Even though no bribes presented themselves, no bribes were accepted, nor would they would have they been. All efforts in this project were intended to improve our group’s understanding of technology, its appropriate application, and potential consequences. Before any movements were taken on the part of the group, thorough research and comprehension was performed to ensure that the project stood within any pertinent limitations. Technical critisim was welcomed and sought by all members in an effort to acknowledge, learn from, and correct errors. Addtionally, all members openly gave technical critism to those who sought it. All outside contributions to this project were properly accredited in the appropriate manner. No person was ever discriminated against for any reason based upon race, religion, gender, disability, age, national origin, sexual orientation, gender identity, or gender expression. No action from any of our members injured anyone, their property, reputation, or employment by false or malicoious action. Lastly, all members assisted colleagues and co-workers in a professional manner to provide helpful development and to support them in following the aforementioned IEEE Code of Ethics. Every possible action was taken to make this project safe, enjoyable, and rewarding for every entitiy involved.

Legal Considerations

To our knowledge, our device does not violate any legal regulations. Pulse transmissions from our two Remotes are from commercially avaiable devices, and are within the 38kHz range common with most commerical IR devices. Use of lab equipment was authorized with prior permission from the lab staff.

Source: A RGB LED Matrix Clock

The post A RGB LED Matrix Clock appeared first on PIC Microcontroller.

PIC16CXXX real time clock electronic project

$
0
0

A very simple real time clock electronic project can be designed using the PIC16CXXX microcontroller family , designed by Microchip Technology . This real time clock electronic project uses the Timer1 module, from a mid-range PIC16CXXX microcontroller, to control a low-power real-time clock. Timer1 was chosen because it has its own crystal which allows the module to operate during sleep.

PIC16CXXX real time clock electronic projectUpon power-up, the device is initialized with the display starting at 12:00 PM, and Timer1 is configured to generate an interrupt (every second). The Timer1 overflow interrupt wakes the device from sleep. This causes the time registers (HRS, MIN, SECS) to be updated. If the SECS register contains an even value (SECS<0> = 0), the colon (“:”) is not displayed. This gives a visual indication for each second. Then the device returns to sleep.

For setting the clock are used three keys : SELECT_UNITS Key (S1) selects which units are to be
modified (hours, minutes, off), the INC Key (S2) increments the selected units and CLR_MIN Key (S3) clears the minutes and seconds (useful for exactly setting the time ) .
This simplify design use a standard Hitachi LCD display module and some other electronic parts .

PIC16CXXX real time clock electronic project SchematicThe RA2:RA0 pins are the control signals to the LCD display, RB3:RB0 acts as a 4-bit data bus, and RB7:RB5 are the input switches. The OSC1 pin is connected to an RC network, which generates an approximate 4 MHz device frequency. Because Timer1 operates asynchronously to the device, the device’s oscillator can be configured for RC mode.
Timer1’s crystal is connected to the T1OSI and T1OSO pins. A good choice for a crystal is a 32.786 kHz (watch) crystal.
This electronic project and source code was designed by Mark Palmer Microchip Technology Inc.

 

For more detail: PIC16CXXX real time clock electronic project

The post PIC16CXXX real time clock electronic project appeared first on PIC Microcontroller.

Digital Clock Using Microcontroller 89C52/89S52

$
0
0
Are you a beginner in micro controller projects?and are you stuck where to start from?if yes,then this is one of the simplest mini projects that you can start from . This mini project will give you a clear understanding of programming your micro controller. we sometimes look at our watch and wonder ” how does this thing work”. Well, in this digital clock project, you will gain some insight on how micro controller can be used to make it work as a Digital Clock.

Digital Clock Using Microcontroller 89C52 89S52 Components required:

  • 1 microcontroller 89C52(89S52 will also do)
  • 2 ceramic capacitors-22pF
  • 1 switch(button for reset purpose)
  • 1 electrolytic capacitor-10uF,25V
  • 1 crystal oscillator-11.0592MHz
  • 16×2 LCD display
  • 1 resistor-10k

Software you will need

This project has been done in proteus software.If you are new to proteus software, the tutorials given below may get you started with the software.note:if you are familiar with proteus you can skip this part.



The programming of the microcontroller is done using keil compiler.port 2 of 89C52 is used as the output port.whereas port 1 is used as the input port.when P1_4 is grounded the 12 hr mode is activated and when P1_5 is grounded the 24 hr mode is activated.
Digital Clock Using Microcontroller 89C52 89S52 Schematic

The detail explanation of the code is done below:

#include “REGX52.H”
#include “delay.h”
#include “lcd.h”
void main(void)
{int hr=0; /*initiate hour=0 */
int min=0; /*initiate minutes=0 */
int sec=0; /*initiate seconds=0 */
P1=0xff; /*set port 1 as input port */
P2=0x00; /*set port 2 as output port*/
while(1)
{ LCD_INIT(); /*initialize LCD*/
if (P1_4==0)/*if P1_4 is grounded enter the 12hr loop */{

The post Digital Clock Using Microcontroller 89C52/89S52 appeared first on PIC Microcontroller.


Darkroom Timer using PIC16F84 microcontroller

$
0
0

Source Code for PIC16F84 and CD4511 decoder

Also, there is an updated version with NPN drivers replacing the 4511 and many new features by Brendon Archibald [websales   optusnet.com.au]

DARKROOM TIMER

Darkroom Timer

The purpose of this project is to present a device that is useful and at the 
same time demonstrate to the beginner many features involved in programming 
the PIC.  Some of the topics included are:

  *   Simple use of MPASM assembler
  *   Demonstration of use of timer 0 and the prescaler
  *   Use of length of instructions to set up timing delays
  *   Using interrupt routines
  *   Detection of switch closures including debouncing
  *   Saving and recovering data from the onboard EEPROM

DESCRIPTION

When the unit is turned on the last used starting count, minutes 0-99, 
seconds 0-59, is showing on the display.  The start count is held in data 
EEPROM of the PIC16F84.  Countdown starts when the start button is pressed.  
An alarm is sounded when the count reaches zero.  The alarm continues until 
start is pressed again.  This press also returns the starting count to the 
display.  Pressing start before reaching zero also returns to starting 
conditions.

The start count can be changed if the set button is pressed before countdown.
Each digit is lit in turn, incrementing from zero until the set button is 
pressed again.  The new start count is saved in EEPROM after the final press 
of the set button.

There are 15 settable start counts.  You cycle through them using the select 
pushbutton.  The set button changes only the starting count presently 
displayed.

MPASM

The source code for MPASM is in the file 'CNTDN.ASM'. It's about as simple as 
you can get as far as assembler directives go.  'LIST' defines the processor, 
while additional code brought in by '#INCLUDE' define all special function
registers, bits etc. #DEFINEs are used to make the code clearer.'ORG 0' says
to start the code at location 0 and 'END' marks the end of the program.

Labels start in the first column.  Both the equates and destination lines have
labels attached to them. Everything else starts in column 2 or beyond. #define
and #include could optionally start in column 1 also.   Look over "p16F84.inc"
to see all the definitions included. Individual bits of registers have names
which should be used rather than numbers, i.e. STATUS,Z rather than STATUS,2.
Defines replace the corresponding numbers involved and make things clearer, 
( PORTA,START_PB rather than PORTA,7).

When you assemble 'CNTDN.ASM', you will get a number of warnings and messages. 
The warnings are because of the instructions 'TRIS' and 'OPTION'.  Ignore them, 
it's the easiest way to set up these registers.  The messages are because MPASM 
can't keep track of which page you are in.  Just make sure that RB0 of STATUS 
has been set before the instructions mentioned are reached and cleared
afterwards.

THE CODE

There are two routine going on at the same time.  The main routine sets 
initial conditions and then loops, checking switches and for an alarm flag at
termination of the count. An interrupt routine does the multiplexing of the
display and decrements the count every second if a countdown is in progress.
It also sets an alarm flag when the count reaches zero.  The interrupt is
based on the overflow of timer 0, (TMR0). 
Schematic Darkroom Timer
TIMING

Two methods of timing are used in the program, TMR0 for the interrupt routine 
and instruction length timing for delays in switch debouncing and alarm 
generation.

SETTING UP TIMER ZERO

TMR0 setup is complicated.  Timer zero continually increments.  When it rolls 
over, a flag, T0IF in the INTCON register, is set.  We are responsible for 
clearing the flag in software.  If we wanted, we could just poll this flag.  
This requires a loop, constantly checking the flag.  A better way is to 
enable timer zero interrupt, (T0IE in INTCON = 1), and enable interrupts in 
general, (GIE in INTCON = 1).  With both bits set, an overflow of TMR0 will 
raise T0IF and cause a CALL to location 4 which is a jump to the interrupt 
routine.

GIE is cleard when the routine is entered so other interrupts won't 
interfere.  GIE will be reset at the end of the routine by RETFIE, (return 
and enable GIE).  Don't forget to clear T0IF or we are right back in the 
interrupt situation again.  Code is also necessary at the beginning and end 
of the routine to save and restore the values of W and the STATUS register.  
Remember, there is another routine going on, (MAIN), which may require these
values.  Saving these is a little tricky because we can't use any 
instructions that change the value of STATUS to do it. SWAP seems to work.

When we start up the PIC, TMR0 is set to increment on pulses from Port A bit
4 pin, (T0CS in OPTION = 1). Clear T0CS, (Timer 0 Clock Select), to 0 to make 
TMR0 increment with the instruction cycle. This is every microsecond for a 
4Mhz crystal.  TMR0 will overflow after 256 microseconds.  This is too fast.
We use the prescaler to slow the rate down.  The prescaler comes up assigned 
to the watchdog timer, (PSA of OPTION = 1).  PSA = 0 will assign it to TMR0.
While we are talking about OPTION, bits 0-3 control the division ratio for the 
prescaler.  We set bits 0 and 1 to get a 1:16 rate.  This gives an overflow 
every 256 X 16 = 4096 microseconds.  All of this adds up to putting a 3 in 
the OPTION register.     

I told you it was complicated.  The good part is that once it is set up it 
just goes on automatically in the background.  Every 4 milliseconds the 
interrupt routine is entered.  The digit to display is changed and the value
from the appropriate register, (SEC, SEC10, MIN or MIN10), is sent to the CD4511
,(through Port A), where segments to be lit are decided.  A pattern is selected
to turn on the appropriate transistor and sent to Port B. Every second a call
is made to EVERYSEC which decrements the count and checks for 0000.  If zero is 
reached the flag bit in ALARM is set.

One more additional complication is the exact timing for 1 second.  A counter 
INTCNT is decremented each time the interrupt routine is entered.  It is 
normally initially set to 244, (H'F4'). 244 X 4096 = 999424 microseconds, 
slightly less than 1 second.  Every 7th time it is set to 245 instead, through 
the use of the counter FUDGE.  This is 1003520 microseconds. The average 
works out to 1000009 microseconds.  Not perfect, but pretty close.

To review the interrupt procedure:
  * There are 4 conditions in the PIC that cause interrupts.  Each condition 
    raises a flag in INTCON.  This happens independent of the state of the 
    enable bits.
  * Each condition has an enable bit which when set indicates that a interrupt
    should be considerd.  If GIE is also set an interrupt will occur and a 
    call made to location 4.
  * We are interested only in the interrupt that can occur when TMR0 rolls 
    over from 255 to 0. By using the prescaler, we make this happen about 
    every 4 milliseconds.
  * GIE is used to disable all interrupts by going to zero when any of the
    interrupt conditions occur. This prevents any further interruption while 
    the current interrupt is being serviced.  GIE is reset by RETFIE.
  * You have to remember to clear the flag set by the interrupt condition in 
    the interrupt routine itself.  Otherwise the condition applies as soon as
    you exit.
TIMING USING INSTRUCTION LENGTH

TMR0 is handy when something has to occur at regular intervals.  Sometimes we 
just want to delay for a set period of time.  This can be done with timing
based on the instruction length, one instruction cycle for most instructions, 
two if the program counter has to be changed. Timing routines appear at the
end of the program.  Based on a 4Mhz crystal the routine at ONEMSEC takes one
millisecond, if you include the two microseconds necessary for the call.  In
similar fashion NMSEC take the number of milliseconds in W when the routine is 
entered.

The most elementary loop in the timing routines is at MICRO4.  Each time 
through this loop requires 4 microseconds, (two single cycle instructions 
and one two cycle instruction).  Notice that when W goes from 1 to 0, the
last time through takes 3 microseconds. Call with 249 in W and the total time 
looping adds up to 995 microseconds.  Add 2 for the call, two for the return 
and 1 for the load of W and you end up with exactly 1000 microseconds.

For multiples of 1 millisecond, (NMSEC), we need to load an external counter 
and keep track of this counter as we go through a number of loops.  Since we 
have to allow for any number of loops 1-255, the best we can do is make each 
loop come out 1 msec and ignore the slight over head getting into the looping 
situation.  This would be 4 microseconds to load W, do the call and load 
CNTMSEC. 

SWITCH DEBOUNCING

A couple of routines are used in switch debouncing.  The problem here is that 
when you press or release a pushbutton it is not a simple matter of going 
from one state to another. 

Normally open push button are attached to Port B pins RB7, (start), and RB6,
(set).  The port pins are set high by activating internal pull-ups.  Pull-ups
are not activated upon power on reset.  To activate them you make sure bit 7
of OPTION is low. When you push one of these buttons, connection is made with 
a contact that is grounded.  This will pull the pin low.  The problem is that 
the contact bounces and the connection is made and broken a number of times 
before the contacts settle down into the closed position. Each time the 
contact bounces off, the pull-ups will try to pull the pin high again. The 
contact may not go all the way back to the original position but if the level 
is high enough for even a microsecond the PIC can interpret it as an 'OPEN'. 
A similar problem occurs when the pushbutton is released.  The problem is not 
as bad in this case though because the contact has to bounce all the way back 
to the orignal closed position in order to be interpreted as a 'LOW'. Some 
switches are a lot less 'bouncy' than others.

What can we do about the problem?  One solution is to put a capacitor across 
the switch.  If it is about the right size,  the time it takes to charge 
prevents rapid changes of the state of the pin and sort of average out the 
bounces which usually last only a milliseconds or two.  You would have to 
play with the size to find what works, usually something between 0.01 and 0.1 
mfd.  Another electronic solution is a RS flip-flop for each switch.

The solution can be done in software. The idea is to look at the situation 
every few milliseconds and find three or four times in succession when the 
reading is the same.  Another solution, if you have the time, is to simply
check start at the first indication of say a closure and then wait long enough
for any bouncing to have stopped before checking again. If you get an opposite
reading you ignore this as a closure.

If you can assume that the switches start high and any initial low comes 
from pressing a switch you can ignore bounces on the press. Go to the routine 
required by the press and wait for a release at the end of the routine.  
Notice that the wait for release routines are just that, they lock you 
in a loop until the key is definately released.  Even if the switch were 
still bouncing from the press, that would be ignored. This is the method 
used in the program.  You see it used throughout the set digits routine as
well as in the main loop. Even before the main loop is entered, three waits in 
a row make sure no buttons are pressed.

SAVING STARTING COUNT IN EEPROM

The routines for saving and recovering data from data EEPROM are straight 
out of the Microchip literature.  There are magic sequences involved that I 
don't understand.  I just used the code provided.  One thing that caused me
some trouble was forgetting to disable interrupts before writing to the EEPROM. 
This could have been done in the routine WRITEE but I chose to do it in the 
routine SETDISP at the end, either side of the call to PUTEE and in the routine
SETSELECT just before and after WRITEE.

Initial data is placed in EEPROM when the PIC is programmed using the DE 
directive at the end of CNTDN.ASM. Location 0 of EEPROM holds an offset which 
decides the four locations holding digits to be placed in the display for the 
starting count.  Location is initially set to zero and then incremented by 
four each time the select pushbutton is pressed. The four selected locations 
are modified and replaced by using the set pushbutton.

SUGGESTED MODIFICATIONS

I used three AA alkaline batteries for a power source.  The unit draws about 50 
ma. so these should last a few hundred hours.  You could use a power line 
operated 5 volt supply.

If you use high efficiency LEDs for the display you might increase the 
size of the 150 ohm resistors and reduce the current/segment to a few 
milliamperes.  If so, you could do away with the transistors.

The unit could be built without the CD4511 decoder.  This chip provides at 
least two advantages:
    1.  It frees up 3 I/O lines and prevents having to multiplex the switches.
    2.  It simplifies the code by selecting the segments to be lit. It also
        blanks the display when an illegal #, like hex A, is entered.
You could do away with the chip, select the segments in software and multiplex 
in the switches, ( which will take a few more resistors to isolate them from 
the displays).

I actually didn't like the sound of the piezo speaker in the schematic.  I 
added a couple of transistors and a speaker I found from an old digital clock, 
(it was 50 ohms either side of center tap).

Pushbutton switches vary considerably in quality.  The ones I used were pretty 
cheap and seem to have trouble on making contact sometimes.   

OVERLOOKING SOMETHING IMPORTANT
 
I originally rushed getting this project out.  I built the unit, wrote the 
code and it worked, (not the first time of course).  I then read in Piclist
of another method of using TMR0 for timing.  It involved writing a count to
TMR0 so the remaining counts to the 255 to 0 rollover would give the desired
time.  I never even thought of doing it this way, I always just used the whole
256 counts.  Then it struck me.  The timing of the first second could be way 
off.  TMR0 is running continually and could have any value 0-255 when the 
button is pressed.  You of course have to set it to zero to get the full 256 
counts.  This made me realize that something else could be wrong.  You have 
the option of cancelling a count down.  This means that INTCNT doesn't 
necessarily get to zero and get reset.  Better reload INTCNT too just to 
make sure.  The moral ... just because something looks like it is working 
doesn't mean it actually is.

See:

Questions:

  • spamavramovski at KILLspamgmail.com asks: “ Can I use tree peen ceramic filter oscillator instead crystal showed in schematic diagram. Best regards.
    Petar from Macedonia.” +
  • i want to ask, will it work properly when using PIC16F84A??? James Newton replies: Yes, the A version is backwards compatible.++
  • asks:
  • James thank you for the circuit you have provided.
    I’ve built the circuit and flashed the PIC and all works perfectly!

    I was just wondering if you have a modification to the code so that it can count hours and minutes rather than minutes and seconds?

    Thank you,

    Rob

spamrobert at KILLspamroberthurd.co.uk asks:

The Capacitor inline with the Peizo speaker, is it 0.05uF or nF?
This is my first circuit using an Oscillator, can you recommend a Crystal I should use. When searching on rswww.com I see 4pin and 2pin crystals, so i’m slightly confused what to use.

With the crystal what are the two capacitor looking components between the crystal and Vss? They seem to have no values, so I assume their not capacitors. Could you please advise me.

Thank you, Rob Hurd

James Newton replies: Capacitor values are generally uF unless other specified. 2 pin crystals are what I’m used to. The components on either side of the crystal are very small capacitors. See PIC oscillators for more information.

spamkontotas at KILLspamceid.upatras.gr asks: “ Is there any other pnp transistor which I could use, because I cannot find 2N223 at the local market?? Maybe one of later technology?” James Newton replies: I guess 2n223 is “old hat” these days. I’m told the current selection includes 2N3906, 2N2907, BC557 for small (100mA) loads, BC327 for 500mA, and ZTX751 for very large (2A) loads.

spamkontotas at KILLspamceid.upatras.gr asks: “ I would like to do the project which is described above, but I cannot understand what kind of pnp transistor sould I use. ” James Newton replies: The standard 2N223 should be fine.

Comments:

spammicrocej at KILLspamgmail.com Hello! I’m Edgardo from Buenos Aires and I would like to know what do I have to change in the code for a 24 hour countdown timer. Thank you!”

Source: Darkroom Timer using PIC16F84 microcontroller

The post Darkroom Timer using PIC16F84 microcontroller appeared first on PIC Microcontroller.

PIC16F877 timer1 code and Proteus simulation

$
0
0

This PIC16F877 microcontroller tutorial answers the question,
” How to use timer1 of PIC16F877 and how to handle its interrupts? ”

PIC16F877 timer1

Using PIC16 simulator (Proteus) you can verify this PIC timer1 code and change it according to your needs. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.

It is assumed that you know how to blink an LED with PIC16F877 microcontroller. If you don’t then please read this page first, before proceeding with this article.

The following diagram (made in Proteus) shows the PIC microcontroller circuit diagram.

In this circuit, PIC16F877 is running on external crystal of 20MHz value. RB0 pin is toggled every time timer1 expires and executes it’s ISR[1] code. In the above figure, it is clear that after approximately every 13msec, RB0 pin is toggled i-e timer1 expires. You can easily change this value in the code.

PIC16F877 timer1 Schematic

Code

The main function code is shown below.

Downloads

Timer1 code for PIC16F877 was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.

 

For more detail: PIC16F877 timer1 code and Proteus simulation

The post PIC16F877 timer1 code and Proteus simulation appeared first on PIC Microcontroller.

Big 7-segment Digital Clock

$
0
0

Using only 2 capacitors, 3 resistors, 4 BIG seven-segment Display, 1 xtal, 2 switches ,and 1 Microcontroller PIC, you can build this Digital Led Clock main circuit.

Big 7-segment Digital Clock

you can use common anode or common cathode display, just select the display type. Here is the pinout information:(I have attach the all diagrams of parts and 7 segments)
I’m used 4x 6″ big 7 segment display’s.

Step 1: Simple paper copy schematic

Big 7-segment Digital Clock Schematic

here is the schematic and part list for the project.
IC – PIC16F628 / PIC16F84A

Step 2: Collect your parts:

4x  6″ big 7 segment display
PIC16F84A
3x 10K Resistors
2x  tack switches (micro switches)
4MHz Cristal (XTAL)
2x  22PF
If you are planing to protect your IC you should connect the IC through 5V regulator (1x 7805)
Vero baord(I used dot matrix board)
and other 7 Segment driver circuit parts displayed with attach image.

Step 3: Solder your all parts

Solder your all parts on to your vero board matching with this Circuit diagram.
Please do not solder your PIC16F84 on your board.Fix that through 18 pin IC base or Zif socket.

Step 4: Make your enclosure

Make a enclosure box  for clock.(makes with plastic acrylic sheet + glue)
and completed circuit board and 7segment board fix on your back plastic acrylic sheet.
and fix the Hour and Mins adjusting button to your enclosure right side panel.

Step 5: Programe Your PIC16F84

I have attach the HEX (16F84 clock) file for this clock.You have to burn it into your chip well.

Source : Big 7-segment Digital Clock

The post Big 7-segment Digital Clock appeared first on PIC Microcontroller.

Digital Clock using PIC Microcontroller Interrupt – XC8

$
0
0

A Real Time clock (Digital Clock) can be made easily by using Timer 1 of a PIC Microcontroller.
The Timer1 module exists in most of the series of PIC, this module can be used to easily implement a real-time clock. Instead of an external real-time clock device like a DS1307, an inexpensive 32.768 kHz watch crystal and two 33 pF capacitors are used to complete the circuit.
In this application, Timer1 is clocked by an external crystal (32.768 kHz) connected across RC0 (T1OSO) and 
RC1 (T1OSI).

Digital Clock using PIC Microcontroller Interrupt - XC8Timer TMR1 module is a 16-bit timer/counter, which means that it consists of two registers (TMR1L and TMR1H). 
It can count up 65.535 pulses in a single cycle before the counting starts from zero.
These registers can be read or written to at any moment. 
In case an overflow occurs, an interrupt is generated if enabled.

Circuit Diagram

As shown on the circuit diagram above on figure 1, an external 32.768 kHz watch crystal and two 33 pF capacitors are connected to Timer1 on PORTC, RC0 (T1OSO) and RC1 (T1OSI). 
The PIC uses an internal oscillator and the MCLR is disabled. If an external oscillator is needed, it can be connected to pins 9 (OSC1) and 10 (OSC2) and if the MCLR is needed to reset the PIC, it can be connected to positive supply via a 10K resisitor.
Time and Date are read from a Personal Computer (PC) via a serial connection. A MAX232 IC is used to convert the voltage logics from the PIC to RS232 standard and vice versa. To learn more on serial connection, please refer to the article: PIC Microcontroller Communication: The RS232. 
When power is switched on, a message will be sent to the PC to set the date and the time. 

A 16 x 2 lines LCD display is connected to PORT B. refer to the Interfacing LCD Display with PIC microcontroller article to learn more.
LED D1 flashes each second as the clock is running.

Digital Clock using PIC Microcontroller Interrupt - XC8 schematicCode

MPLAB XC8 compiler is used to write the code. 
The PIC18 Peripheral Library found inside the installation folder of CX8 compiler contains a full description of Real-Time Clock and Calendar (RTCC) function simulated using Timer1. 

Open_RTCC(): Configures Timer1 to work as clock source for RTCC, enables Timer1 interrupts, and writes a value into TMR1H & TMR1L registers to get 1second interrupt.
update_RTCC(): checks for the TMR1 interrupt flag, refreshes TMR1H if interrupt has occurred and returns the state of TMR1IF 

 

For more detail: Digital Clock using PIC Microcontroller Interrupt – XC8

The post Digital Clock using PIC Microcontroller Interrupt – XC8 appeared first on PIC Microcontroller.

Digital Count Down Timer using PIC Microcontroller

$
0
0

In this article, our author Mithun has developed a 0 – 99 min counter using PIC microcontroller 16F628A. So basically this is a digital count down timer ideal for engineering and diploma students for their project requirements. We have given complete circuit diagram of the digital count down timer along with full source code. In addition, photographs of the breadboard setup is uploaded.

Every micro controller has a timer unit inside. A timer is nothing more than a time counting device fabricated inside the micro controller unit. A wide range of practical applications require a timer in action.

Digital Count Down Timer using PIC MicrocontrollerFor example, we need to turn a motor ON for 5 minutes and then turn it OFF as part of a particular project; how will we do that? A timer inside a mircocontroller unit aids us in implementing this perfectly. A timer can be used to count the 5 minutes exactly and the bits that get SET at 5 minutes limit can be used to program the controller to turn OFF some device(s).

I hope you got a basic idea about timer unit and its practical applications. We are going to make this project using an LCD display, PIC controller 16F628A and a 4 MHz external crystal to provide the necessary clock. We will be writing the codes using micro C.

In any project that involves an LCD, the first step is to initialize the LCD module. We have written detailed articles about interfacing LCD to an MCU before. You can learn more about Interfacing an LCD to 8051  and Interfacing LCD module to AVR controller in these articles. If you want to learn more about character LCD displays in detail, this tutorial on Character LCD displays will be of help.

Now, we need to configure relay and switches. The code snippet for the same is given below.

Here ‘sbit’ stands for set bit. You can do the same another way using “#define” command. This line means that  RA3 pin will be known as the Relay/ RB0 pin will be known as etc.

Even though the project name “digital count down timer” sounds so silly, its operation is not that simple. We have given below a proteus diagram of the circuit to explain the project perfectly.

Analyzing the circuit diagram, you can see three buttons . One button is for Start/Stop function and the other 2 buttons for Units & Tens counting. We will configure our LCD module with display messages corresponding to the button configurations

These are the messages we will be showing in our LCD. To control the system we’ll need some other variables as well. These variables are declared in the code snippet given below.

Digital Count Down Timer using PIC Microcontroller SchematicLets understand the counting mechanism now.  The circuit is wired in such a way that, the user will have to select the limit of counting initially. If the user is interested in counting 1 to 9 minutes only, then he is supposed to press the units button alone. If he is interested in counting 1 to 99 minutes, then he should press the Tens button along with Units button.  Once he sets the limit, he should press the Start/Stop button to start the timer (its a push button switch and same button switch is used to stop the timer as well).

Note:- Since the timer operation depends upon the value selected by user (units and tens switch), we have to check certain possible error conditions before starting the timer. Assume a condition in which the user forgot to select units or tens switch and pressed the start/stop button directly; what is supposed to happen in this scenario? It’s an expected error condition that should be handled inside the software. A common way to handle this scenario is to start the timer only if the limit value is greater than zero. The code snippet given below handles this condition.

 

For more detail: Digital Count Down Timer using PIC Microcontroller

The post Digital Count Down Timer using PIC Microcontroller appeared first on PIC Microcontroller.

PIC Countdown Timer using PIC16f84a

$
0
0

Description :

The purpose of this timer is to provide a countdown time from 1 second to 99 minutes & 59 seconds. I use it to control the lighting for the Ultra-Violet exposure of photosensitive PCB material. The project provides also an audible alarm at the end of the countdown time and switches the UV lights by means of a relay. It is based on a Microchip microcontroller, the 18 pin PIC16F84(A). This microcontroller contains 1Kbyte of flash memory for program code, 64bytes of static RAM memory, and 64bytes of EEPROM memory which are used here to store up to 15 different (user-programmable) countdown times.

PIC Counter 16f84a

The Power Supply Unit (PSU) schematic is simple and straight :
The 2x9VAC from a 3VA transformer is rectified by diode D5 & D6 and smoothed by C11 & C12 to obtain about 12VDC voltage.
This 12VDC is then used to feed voltage regulators IC5 & IC6:
– IC5 (7805 regulator) delivers the +5V voltage for the logic (PIC, 4543, relay and buzzer).
– IC6 (7808 regulator) delivers a +8V voltage to feed the four blue Common Anode displays.
If other display colours are used (red, green, yellow) the +8V power supply can be omitted and the displays feeded by the +5V for the logic.

The main schematic :
The main part in the schematic is of course the PIC16F84.
It takes care of the scanning of the pushbuttons, multiplexing the display output and activation of the relay and buzzer while running several timing routines for accurate countdown.
Fifteen countdown times can be stored into EEPROM memory. The timer starts automatically with the countdown time stored in the first EEPROM memory location.

pcb

The lower nibble of PORTA is used to drive the 4543 ‘BCD to 7-segment driver/decoder’, the lower nibble of PORTB to drive the 7-segment digits through transistors T1 to T4.

Three push buttons allow for user input:
S1 – START/STOP push button: Starts the actual displayed count down time, or interrupts (stops) the countdown in progress.
S2 – SET push button: Allows to set the desired countdown time by litting every digit in turn (every push lits the following digit: M10,M1,S10,S1).
Waiting between pushes increments the active digit by one every second. After the last digit (second units) has been set the configured countdown time is automatically saved into the active EEPROM memory location.
S3 – SELECT push button: Allows to browse through the 15 EEPROM memory locations to retrieve the desired stored countdown time. Setting a new countdown time through the SET push button stores it automatically into the active memory location.

A 50ms beep from the buzzer confirms every key press.
At the end of the countdown time (00:00) the buzzer sounds intermittently (1Hz, 0.5sec on, 0.5sec off) until the START/STOP button is actionned, and the initial countdown time is displayed again for a next countdown.

Timer0 overflow interrupt is enabled and the prescaler (16) is assigned to Timer0. With an oscillator frequency of 4MHz this gives a Timer0 overflow (and interrupt) every 4.096 msec: 1 / [ ( 4000000 / 4 ) * 16 * 256].
When programming the 16F84(A) set the configuration word to 3FF2h : CP disabled, PWRT enabled, WDT disabled, HS oscillator enabled).

As the 16F84(A) becomes obsolete and more expensive than the 16F6x8 (16F628 with 2KB program memory, and 16F648 with 4KB) which are pin-compatible, I made also a firmware version that works with these (CNTDWN3-628-PNP.ASM), and the corresponding HEX file.
The only differences with the 16F84 firmware are:
– Initialization of PORTA as digital I/O ports (default is A/N ports).
– Relocation of the GPR (General Purpose Registers) variables from OCh to 20h.
– Modification of Indirect Addressing Pointers to point to the new GPR addresses.
– Modification of the bank selections when accessing the EEPROM memory.

When using a 16F6x8 instead of a 16F84, the 4MHz crystal (XTAL1), the 22pF capacitors (C1 & C2) and the connection of the MCLR pin to +5V can be omitted as the 16F6x8 microcontrollers series include an internal calibrated 4MHz RC-oscillator which is set by configuring the correct bits of the configuration word during programming (2149h : CPD disabled, CP disabled, LVP disabled, BOR enabled, MCLR internally, PWRT enabled, WDT disabled, Internal oscillator enabled).

 

For more details visit: PIC Countdown Timer using PIC16f84a

The post PIC Countdown Timer using PIC16f84a appeared first on PIC Microcontroller.

PIC16F84A timer0 code and Proteus simulation

$
0
0

This post provides the timer0 code for PIC16F84A microcontroller. This code is written in C language using MPLAB with HI-TECH C compiler. You can download this code from the ‘Downloads‘ section at the bottom of this page.

PIC16F84A timer0

It is assumed that you know how to blink an LED with PIC16F84A microcontroller. If you don’t then please read this page first, before proceeding with this article.

The result of simulating the code in Proteus is shown below.

In this circuit, PIC16F84A is running on external crystal of 20MHz value. RA0 pin is toggled every time timer0 expires and executes it’s ISR[1] code. In the above figure, it is clear that after approximately every 100usec, RA0 pin is toggled i-e timer0 expires. You can easily change this value in the code.

Code

The code used to initialize timer0 is shown below.

In this function, OPTION_REG is initialized to make timer0 prescalar to be 1:2. Timer0 is an 8bit timer, so it expires after reaching a value of 255. When timer0 prescalar is made 1:2 then it means that timer0 value will increment after every two clock cycles. Since PIC16F84A is running at 5MIPS[2] speed, this means that timer0 will expire after every 256*2/5 = 102 usec[3]. T0IE bit enables timer0 interrupts and GIE bit enables global interrupts.
PIC16F84A timer0 schematic
Timer0 interrupt service routine code is shown below.

Downloads

Timer0 code for PIC16F84A was compiled in MPLAB v8.85 with HI-TECH C v9.83 compiler and simulation was made in Proteus v7.10. To download code and Proteus simulation click here.

 

For more detail: PIC16F84A timer0 code and Proteus simulation

The post PIC16F84A timer0 code and Proteus simulation appeared first on PIC Microcontroller.


IN-8 single nixie tube clock using PIC16F84

$
0
0

After receiving one IN-8 tube from a friend (thanks), I decided to build myself a clock. This clock is more an ornament than a useful machine because it consists of just one digit (tube) so it displays current time every minute for three times. It is built inside of an old wooden box and it’s powered from a 7V DC wall adapter. Under a nixie tube there is a very bright green LED which makes everything look more beautiful. When time is not displayed, this LED blinks with 1 second period (seconds counter).

nixie tube clock

To power-up a nixie, some 170V DC is required, which means that there is a step-up converter on board with MC34063A IC.

You can download the project files at the bottom of this page by clicking on red “download” button.

Setting up the time
To set the time press the button and power-up the clock. This will enter the programming mode. Now 00, 00, 00,… will be displayed. Press and hold the button until hours are set. Release the button to switch to minutes. Now do the same thing with the minutes and that’s it! After programming, the current time will be displayed.

Timekeeping and measuring
Inside of this box there is a 3V Lithium battery (CR2032) that keeps the PIC microcontroller running even when the clock is turned off (the wall adapter). This is very convenient because after powering it up again, we don’t need to set the time – again. If a button is pressed during a power-down, nothing will happen. With PIC microcontroller I used a “watch” crystal at 32,768kHz. It’s value is pretty cool and now we will see why. PIC16F84 has internal TMR0 counter that increments itself no matter what the PIC is doing at the moment.

 

For more detail: IN-8 single nixie tube clock using PIC16F84

The post IN-8 single nixie tube clock using PIC16F84 appeared first on PIC Microcontroller.

Determine capacitance by measuring the charging time using PIC16F688

Building your Dream Alarm Clock Using the PIC18

$
0
0

Objective: In this laboratory session, your objective is to create an alarm clock using the C programming language. You will gain proficiency in writing “C” programs for the PIC18 microcontroller. Additionally, you will acquire knowledge on working with interrupts, employing digital-to-analog conversion, and implementing music playback on the PIC18. This is a collaborative project, with …

Building your Dream Alarm Clock Using the PIC18 Continue Reading

The post Building your Dream Alarm Clock Using the PIC18 appeared first on PIC Microcontroller.

Viewing all 218 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>