Showing posts with label PIC. Show all posts
Showing posts with label PIC. Show all posts

Sunday, 24 February 2019

Mini Oscilloscope

Date of completion: 2010-2015

This was my first successful attempt (earlier attempts might be considered part of a steep learning curve!) to construct a small, portable oscilloscope. It also incorporates the extra functions of a stopclock and a voltmeter. For a later, more sophisticated design of portable oscilloscope, see "TFT Oscilloscope". Although the resolution of the graphics display is low and the fastest timebase is relatively slow (it is, however, OK for audio frequencies), the big advantage of this design is its very low battery consumption, helped particularly by having a full, timed power-down mode.

Photos






Design

The input stage of MiniOsc is an instrumentation op amp, giving it a properly differential input with a high input impedance of around 2 MOhms. TTL analogue switches (SN74HC4066) combined with four standard op amps (MC33204) are used to change between DC and AC amplification and for gain control. The ADC is an 8-bit TLC0820. The microprocessor used is a 40-pin PIC18F4550 driven by a 20MHz quartz crystal and it has a reference voltage provided by an LM285 to correct for variations in the power supply. The power supply is either four AA cells or an external power supply stepped down by an LM317 voltage regulator. As the battery is not connected via a regulator, full power-down can be achieved when the p-channel MOSFET (ZVP2106A) is switched off.
There are two LCD displays, one graphic and the other 16-character, both of which are powered via the MOSFET. The PIC, of course, has its own power-down function, reducing the total current drawn to less than 1 microamp when the MiniOsc is not being used. It can easily returned to its state before power-down (after a timeout, which occurs after a few minutes of no button-presses), using the "wake" button.
Programming was performed in Assembler using a number of different linked routines (listed below.) With a 20MHz crystal it was possible to program accurate oscilloscope timing and triggering, even for several  tens of kSamples per second. This did, however, involve some very careful counting of program cycles!

Circuit Diagram

Tiny CAD (.dsn) files: MiniOsc3


Source code and other files

MiniOsc.asm  MiniOsc.inc  Control.asm  GLCD.asm  LCD.asm  Menu.asm  Sample.asm  Stopclock.asm  Volt.asm   All files (.zip)

Saturday, 23 February 2019

Speed of Light Apparatus

Date of completion: 2015

When teaching either the topic of Total Internal Reflection (of light) or Communications to GCSE students I always felt that it would be much better to see optical fibres in use than simply to talk about them. The device here measures the time for an optical signal to travel along an optical fibre, and from this a fairly accurate value for the speed of light in a glass fibre can easily be calculated.  This is clearly useful when teaching about refractive index. I bought a 100 metre reel of double optical fibre from Ebay (ensuring it had the correct optical connectors) and then another much shorter length of optical fibre (blue in the picture) to return the output signal back along the input fibre (making a total length of just over 200 metres.) Given that the refractive index of glass is about 3/2 and so the speed of light in it is about 200,000,000 m/s, this gives a time delay of roughly 200 / 2 x 10^8 seconds or 1 microsecond. This is just measurable using a 50 MHz oscillator and its accuracy is greatly improved by averaging over multiple transits.
Inevitably there a delay due to electronics response times (about 2 microseconds, dependent temperature), but a reset button was added to subtract this from the times displayed once the unit had warmed up (about 10 minutes) to keep the demonstration simple for GCSE students!

Photos and School Instructions


Design

The hardest part of the project was finding a cheap optical transceiver on Ebay, but it wasn't long before I spotted one buried in an old non-functioning electronics unit. It turned out to be an HFBR 5803 and a search on the internet revealed its characteristic were just fast enough to make a reliable timer. Some level shifting of input and output voltages was needed, but it became apparent that with the help of an op amp it could be connected to a resettable gate made from fast TTL NAND gates in a 74HC132. This is controlled by a PIC16F628A (my favorite!) and the output is displayed on a 16 character LCD (also my favorite!) The 5 volt-powered 50 MHz oscillator came, as ever, from Ebay, and these signals are fed through the gate to the PIC which counts them repeatedly (via its TIMER0, set up as a fast counter.)
The coding is performed in assembly language so that timings could be calculated easily and reliably (with the PIC driven by a 20 MHz quartz crystal.) Most of the coding is concerned with calculating the time correctly and displaying it on the LCD display.

Circuit Diagrams


Tiny CAD (.dsn) files: Light2

Source code and other files

Light2.asm  All files (.zip)

GPS clock

Date of completion: 2018

This GPS clock was designed to replace the radio controlled clock mentioned in another blog post. The radio signal from Cumbria was rather weak and unpredictable, whereas the GPS signal near a window is much more dependable. I enhanced it a few years later to incorporate the church alarm receiver, also mentioned in an earlier post. Not only does it indicate if the church alarm is sounding (by lighting a green LED in the side of the device - the red LED flashes every 2 seconds to indicate a signal has been received from the church tower 100 yards away), but also how close to the hour the church bell rings. (e.g. the "-9s" in the photo indicates that the bell last sounded just 9 seconds late - not bad for a church clock built in 1850!)

Photos

Design

The design of the church alarm receiver is described in an earlier post, but suffice it to say it uses a cheap 433MHz receiver and HT12D decoder with a 17.3 cm aerial (a bit bent in the photo.)
The GPS unit came from Ebay and its 3 volt RS232 signal (at a baud rate of 9600 bps) is connected to a PIC 16F628A microprocessor (running at 5V), which drives a 16 character LCD display. The PIC decodes the data from the GPS unit to display the time in hours, minutes and seconds, and the current date. Like my earlier radio-controlled clock, the PIC can continue to display the correct date and time for a short while, even if the GPS signal is lost. I have included a table to switch between Greenwich mean time and British Summer Time on the correct dates each year. I think it should currently run correctly until 2026 or so. After that I will need to program the PIC with new data for future dates!
The church bell signal is compared to the GPS time every hour between 4 minutes before and 4 minutes after the hour. This reduces possible confusion with  spurious sounds due to the church alarm sounding (a rare event) or the bell ringers practising (a regular event!)

Circuit Diagrams


Tiny CAD (.dsn) files: GPSClock

Source code and other files

GPSClockX.asm  All files (.zip)

Sunday, 17 February 2019

Organ Transceivers

Date of completion: 2019

This refers to a couple of devices (a "transmitter" and a "receiver") designed and built to facilitate communication between a church leader and an organist. These people are often situated far apart in church services, and the organist needs to be kept up to date about when to start/stop/prepare for playing. This is certainly true in Seal church, Kent, where my wife is the vicar and I sometimes attempt to play the organ!

Photos



Design

Both devices are designed around the CC1101 transceiver, which is a rather sophisticated device from Texas Instruments, but which is very cheap via Ebay. It comes with lengthy instructions and a software program to help with choosing set-up parameters. The devices also each have a PIC microprocessor. I used two quite different PICs (PIC16F1503 and PIC18F2550), as I just happened to have them available, but there are only slight differences in programming details. They are programmed very similarly using C (XC8 from Microchip, who make the PICs), although one is primarily the transmitter and the other is primarily the receiver. They respond correctly to button presses only if there is a two-way communication between them, however.

Each has an on-off switch to preserve battery life, but they are also programmed to enter standby mode after 90 minutes of inactivity. Each has a white light to indicate that it is switched on and is consuming power. I have minimized power consumption by putting the CC1101s either into SLEEP mode or WAKE-ON-RADIO mode (testing for a received signal every 1 second) between transmissions and using the SLEEP mode of the PICs whenever there is activity (waking on interrupts (a) from the CC1101, (b) from a button being pressed, or (c) from the watchdog timer to keep the white light flashing.)

When a transmitter button (red, yellow or green) is pressed a signal is sent to the receiver, which flashes the appropriate LED once and sends back a signal to the transmitter. When this signal is received the transmitter flashes its own appropriate LED once. If the original button is held down, the process repeats until the button is released. There is a HELP button on the receiver, so that the organist can attract initiate communication, if needed. When pressed the red and green LEDs on both devices flash continuously until either the HELP button is pressed again or one of the buttons on the transmitter is pressed.

When first switched on both devices flash all three coloured LEDs once. Error-trapping is enabled by resetting the CC1101 and PIC (and therefore flashing all three coloured LEDs once again) if trying to communicate when, for example, only one of the two devices is switched on. Each is powered by two AA batteries, which should last for several years before needing to be replaced (if my calculations and measurements are correct, and there are no serious bugs in the programs!)

Circuit Diagrams

Tiny CAD (.dsn) files: CC1101 Transmitter CC1101 Receiver

Source code and other files

Transmitter: CC1101T.c  CC1101.h  All files (.zip)

Receiver: CC1101R.c  CC1101R.h  All files (.zip)

Frequency Meter

Date of completion: 2008/2012

This was a fairly early attempt of mine to construct and program a reliable frequency meter using a PIC, based on the efforts of others published via the internet. 

Photo


Design

The power supply comes from a 9V mains adapter feeding a 7805 voltage regulator. The PIC is a (nowadays rather ancient) 16F84A and it is is connected to a 16-character LCD display. The input stage design came from the internet and it feeds into a resettable latch constructed from 4 fast TTL NAND gates (74HC132). The PIC is driven by a 20 MHz crystal, enabling highly accurate timing. The code is adapted from that of Barry Smith, who himself adapted it (in 2006) from that of Terry J. Weeder. It does work, but I can't tell you much about the design!

Circuit Diagrams

Tiny CAD (.dsn) file: Frequency Meter 2012


Source code and other files

Freq2012.asm  All files (.zip)

Radio-Controlled Clock

Date of completion: 2010

I am a Time-Lord! My job is to keep the local church clock, built in 1850, chiming somewhere near the right time. I can hear the chimes from home, but our clocks in the house are generally only accurate to the nearest minute, at best. So I designed and built this radio-controlled clock to display the correct time digitally to the nearest second. Then I could judge how many seconds forwards or backwards I needed to adjust the church clock. The radio-controlled clock uses the LW signal (MSF) transmitted from a site in Cumbria, UK, containing time information from a caesium atomic clock and it is therefore highly accurate. The signal is, however, very weak (we are a long way from Cumbria.) So to avoid having to design and build a receiver tuned to the correct frequency, I deconstructed a cheap analogue radio-controlled clock from Ebay, i.e. I ripped out its receiver and used it here!

Design

The heart of the clock is a 16F628 PIC with a 16 character LCD display. The PIC and display are powered from a 9V mains adapter via 7805 voltage regulator, but I noticed that the MSF receiver needed a single AA cell. It turned out that the output from the receiver is sufficient to drive the PIC, if set up judiciously, and the cell has very little current drawn from it (so rarely needed replacing.)

There are actually two clocks here: the second is run by the PIC itself, which takes over if the signal from the receiver is too weak. An interrupt routine is triggered by the receiver and this decodes the basic information of time and date. Most of the rest of the assembly language program is concerned with formatting for display (hours, minutes, seconds, day, month, year) and error-trapping (as the signal is VERY weak, and the device only works near a window - or, better, outside!)

I no longer have the clock, as I have now constructed a GPS clock, which uses a rather more powerful signal from GPS satellites for time information. See "GPS Clock" for further details.

Circuit Diagrams

Tiny CAD (.dsn) file: Clock


Source code and other files

Clock.asm  All files (.zip)

Saturday, 16 February 2019

Optical Fibre ADC and DAC

Date completed: 2014

Here are a couple of circuits I designed and built for teaching Physics. At the time of the "Big Switchover" from analogue to digital radio and TV, we were required to teach the differences between, and uses of, analogue and digital signals at GCSE. These little boxes encode an input analogue voltage into a digital signal of 8 bits, sends it along an optical fibre, and then decodes it back to analogue (which can be connected to a voltmeter). The whole process is demonstrated slowly with a flashing LED (in a straightforward binary code), or it can be done rapidly, so that a low frequency signal (say 200 Hz) can be sent and listened to via an amplifier and speaker.

Photo and School instructions

Design

These circuits are based around two PICs (different ones, just because those are the ones I had at the time!) Each pic has a quartz crystal to control the timing, and they are powered via 7805 voltage regulators from PP3 9V batteries. The optical fibre connectors were bought cheaply, the aim being to keep the whole setup as visible as possible. TS912N op amps are used to amplify the signals (again because I had some of these available - 741s would have done fine.) Diodes are used for over-voltage or reverse-voltage protection. The programming is in assembly language.

Circuit Diagrams

Tiny CAD (.dsn) file: ADC-DAC


Source code and other files

ADC: ADC.asm  All files (.zip)
DAC: DAC.asm  All files (.zip)