How a Voltage Regulator Works: LM7805

Voltage regulators are one of the first electronic components you get introduced to as a hobbyist. Really useful when starting out, it simply takes a voltage that is too high, and reduces it down to a set voltage that you want, usually defined by the component. Solves the problem of having batteries or power supplies being a different voltage to the thing you are powering (such as your Arduino), and at as little as 50p from ebay they are easily acquired. Sounds like a great solution, but there is an issue, they are terribly inefficient. They are known to get very hot when used at high currents, and often need hefty heatsinks to stop the magic smoke from being released. To demonstrate why they get so hot we need to think about what happens during use. Remembering Kirchoff, the current going into a system is the same as the current going out of the system. If we use a simplified version of the regulator, the only thing this device changes is the voltage of the output. Due to the minimal current lost powering the circuit we assume the vast majority of power lost is in heat. Using the basic equation of:

Power (W) = Voltage (V) x Current (I)

So if we use an example of the LM7805 made by On Semiconductor (previously Fairchild) that can regulate 5V at 1A. It’s a pretty standard component, and is very typical of a voltage regulator.

If we use a 9V input the power going in is 9V x 1A = 9W.

The output power is 5V x 1A = 5W.

This means that there is 4W of power being dissipated from the regulator as wasted heat. This is a large amount when considering the size of the packages available. When thinking about problems excessive heat can cause in a circuit, it can quite easily damage itself and other components around it when not designed properly. It is why there are often big chunks of aluminium attached to the back of the components to act as a heat sink.

7805
7805 chip in a TO-220 package. Notice the heat sink on the rear with a screw mount.

This post isnt meant to dissuade you from using regulators, they have their place in electronic circuits, and are a great starting point. All electronic engineers need to have a broad understanding of the advantages and disadvantages of linear voltage regulators to be able to handle them properly.

How it Works

LM78xx schematic 2 coloured
Schematic of the silicon inside an LM78xx device, coloured relating to the function of each area.

The above schematic can be found on the datasheet, but it’s been coloured in to show the different sections of the circuit.

The most important component in the above schematic is Q16 (Red), it controls the current between the input and output, therefore the voltage. It is placed in a darlington pair configuration with Q15 (Orange). In this configuration Q16 is amplifying the current amplified by Q15. This means that Q15 can be used to introduce error feedback. The Blue section contains a voltage divider that scales the output voltage so that it can be used by the bandgap circuit. This bandgap circuit is found in the yellow section (Q1 and Q6). This bandgap reference produces an error signal that is fed into Q7 (orange). A bandgap is used because it can provide a stable output even when the temperature of the device changes.

The orange section takes this error and amplifies it through Q15 and the darlington configuration described earlier. The purple section has overheating protection (Q13) and excessive output current protection (Q14). Occasionally on these schematics you also find excessive input voltage protection marked as Q19 in this section. These shutdown the regulator in fault conditions like overcurrent or getting too hot. The Green section is known as the “start up” circuit, because it provides the initial current needed to power the bandgap circuitry. This gives a jumpstart to the circuit when it needs it.

I chose the LM7805 because 5V is a common value to be used, but the LM78xx series has many different preset voltage versions. The bandgap circuit is trying to get its input to 1.25V, this is from the voltage divider found in the blue section. As R20 is a variable resistor, the voltage divider can be calibrated during manufacture to output exactly 1.25V at any chosen output voltage. This is great for a manufacturer because they make lots of the same chip, and it can be made to suit any voltage output they want. This is also similar to the way some adjustable voltage regulators work, such as the LM317. In adjustable chips, the voltage divider is made by the designer externally, meaning it can be applied to any situation with a simple change of resistors.

Basic Configuration

Looking at the datasheet, there are many applications for the device. but the simplest one is just an input and an output. All that’s needed is a couple of decoupling capacitors to smooth out AC signals and random noise. Voltage regulators work best with clean, smooth power. There is also the need, due to the voltage drop across the transistors, for the input voltage to be at least 2V above the required output. This is always a good rule of thumb to go by when it comes to regulators.

LM78xx basic configuration
LM78xx basic configuration

I would recommend people read the datasheet and have a play with different voltage inputs and current outputs, see how easy it is for it to get hot. In that datasheet there are some other good applications using the device, you can turn it into an adjustable voltage output, constant current supply and high current supply. These are also good projects for learning more about transistors and op amps. Equally, there are other types and brands of regulator out there, some cheap, and some quite expensive, it is worth shopping around for  the ones that suit you.

Luna 1 – The Satellite That Missed the Moon

Luna 1 was the first spacecraft to reach the vicinity of the Moon. Passing just 6000 km away due to an incorrectly timed upper stage, it was meant to impact the moon and spread Soviet pennants to claim the moon as their own. As the satellite ended up in heliocentric orbit, the Soviets renamed it Mechta (Russian for dream), and heralded it as a successful attempt to make a new planet. It was not until years later that Luna 1 was revealed to be a failed plan to impact the mo0n.

A museum replica of luna 1
A museum replica of luna 1

On January 2nd 1959, at 16:41:21 UTC (22.41 local time) Luna 1 was launched from the Scientific-Research Test-Range No. 5 at Tyuratam, Kazakhstan (now named the Baikonur Cosmodrome). Launched aboard Vostok-L 8K72 three-stage launch vehicle, it was the fourth attempt at sending a payload at the moon by the Soviets. The first 3 were:

E-1 No.1 – or Luna 1958A (NASA designation). Launched 23rd September 1958, 07:40. Booster disintegrated 92 seconds into flight due to Excessive vibration. Was the maiden flight of Luna 8K72 Rocket.

E-1 No.2 – or Luna 1958B (NASA designation). Launched 11th October 1958, 21:42. Booster disintegrated 104 seconds into flight due to Excessive vibration.

E-1 No.3 – or Luna 1958C (NASA designation). Launched 4th December 1958, 18:18. 245 seconds into flight, the core stage turboprops lost hydrogen peroxide lubricant, meaning it lost power and impacted downrange.

E-1 No.4 was only a partial failure, and therefore became known as Luna 1. Intended to impact the surface of the moon. Due to an error in timing the upper (third) stage burn time caused a near miss. After 34 hours of flight, at 3.45 UTC on january 4th the probe passed within 5,995km (3,725mi) of the lunar surface, which is about 1 and a half times the moon’s diameter. It was 320,000km from earth, travelling at 2.45km per second. It became the first man-made object to reach the escape velocity of earth. Then after missing the moon it was the first spacecraft to leave geocentric orbit and enter heliocentric orbit.

A replica of the luna 1 attached to the cone
A replica of the luna 1 attached to the cone

The Luna 1 module was hermetically sealed sphere weighing 361.3kg (795.9lb) with 5 antennae extended from one hemisphere; four whip antennas and one rigid antenna. The spacecraft contained a 19.993 MHz system which transmitted signals 50.9s long, a 183.6MHz transmitter for tracking purposes, and a 70.2MHz transmitter. The batteries on board were mercury-oxide and silver-zinc accumulators. Five sets of scientific equipment were externally mounted to the unit to study the journey including a geiger counter, scintillation counter, and micrometeorite detector, along with a Sodium experiment. The device on the end of the center rod protruding out the back is a magnetometer to measure the moon’s magnetic field.

The primary objectives of the mission were to:

  • Measure the temperature and pressure inside the vehicle.
  • Study the gas components of interplanetary matter and corpuscular radiation of the sun.
  • Measure the magnetic fields of the earth and the moon.
  • Study meteoric particles in space.
  • Study the distribution of heavy nuclear nuclei in primary cosmic radiation.
  • Study other properties of cosmic rays.
    Another schematic of Luna 1
A schematic of the Luna 1
A schematic of the Luna 1, unfortunately with russian annotations

at 00:56:20 UTC on january 3rd, 119,500km (74,300mi) from earth, the spacecraft released 1kg (2.2lb) of sodium gas. This formed a cloud behind it to serve as an artificial comet. The glowing orange trail of gas was visible over the ocean with the brightness of a sixth-magnitude star.  Mstislav Gnevyshev at the Mountain Station of the Main Astronomical Observatory of the Academy of Sciences of the USSR near Kislovodsk took a photograph. This was designed as an experiment on the behaviour of gas in outer space, as well as functioning as a navigational aid helping ground control track the mission.

gas cloud of sulphur
Gas cloud photographed by Mstislav Gnevyshev at the Mountain Station of the Main Astronomical Observatory of the Academy of Sciences of the USSR near Kislovodsk

Luna 1 was made of an aluminium-magnesium alloy and sealed with a special rubber. To protect the satellite there was a cone to take the heat when passing through the dense layers of the atmosphere. When safely out of the atmosphere the cone was discarded, and the antennae unfolded. On the same half as the antennas were two proton traps to find the gas components of interplanetary matter, and two piezoelectric pickups to study meteoric particles. The inside of the unit was filled with gas at 1.3 atmospheres, to ensure high pressurisation inside. Through the design, the high pressure allows for an air circulation within the unit. This circulation drew heat off equipment and instruments, transferring it to the shell, that then serves as a radiator.

The nose cone
A replica of the nose cone in an exhibition in 1969
How it fitted
A diagram showing how the nose and luna probe fitted

The Vostok-L 8K72 was a modified R-7 Semyorka intercontinental ballistic missile.The R-7 rocket was designed by Sergei Pavlovich Korolev, known more commonly as the Chief Designer. The 8K72 version consisted of two core stages with four external boosters. The first stage and each of the boosters were powered by a four-nozzle RD-107 rocket engine burning kerosene and liquid oxygen. Total thrust was approximately 1,100,775 pounds (4,896.49 kilonewtons). The second stage used a RD-0105 engine, producing 11,015 pounds of thrust (48.997 kilonewtons). The Luna 1 was propelled by a third stage which remained attached during the translunar coast phase of flight.

Vostok on Takeoff
Vostok on takeoff with the luna 1 on board

After Luna 1 passed the moon and continued on towards heliocentric orbit, it only had a certain amount of battery power left. Because it was meant to collide with the moon it had no need for recharging. On january 5th at approximately 07:00 the radio transmitter ceased to operate at a distance of 600,000km from earth. It is still in an orbit around the sun, somewhere between mars and earth. It completes one rotation in roughly 450 days. for those who understand the terms associated with orbital mechanics here are the numbers:

  • Semi major Axis: 1.146AU
  • Eccentricity: 0.14767
  • Perihelion: 0.9766AU
  • Apohelion: 1.315AU
  • inclination: 0.01 degrees
Luna1 Trajectory
Luna 1 Trajectory

The main aim of the mission was to hit the moon, the reason was to plant 2 Soviet pennants onto the moon. They were highly durable, made from titanium with thermoresistant polysiloxane enamals, that could reportedly survive an impact with venus. Usually a few are minted to give to VIP’s and top scientists. For them, it’s similar to planting a flag. one of the pennants on this flight was a thin metal strip with the inscription “Union of Soviet Socialist Republics” on one side and the coat of arms of the Soviet Union and the inscription “January 1959 January” on the other. The other pennant was spherical, symbolising the moon, each face has the inscription “USSR, January 1959,” on one side and the coat of arms of the Soviet Union and the inscription “USSR” on the other. These pennants were eventually distributed on the moon by Luna 2.

luna 1 pennant 1

Luna 1 pennant 2
The pennants on the Luna 1, that are still inside the satellite to this day.

 

The Foundry: Drilling an Air Hole

At this point we had a cast foundry base, made out of sand and plaster of paris. To see how that was made, see the tutorial here.  Before we first test it though, we had to make one modification, and that was to drill a 30mm diameter hole in the side of it.

The hole from the outside
The hole from the outside

The idea of the hole is to allow air to come in and fuel the fire. The theory goes that the air comes in the side, and the resultant fumes (like smoke) leave via the opening at the top. It makes sense because heat rises, and takes all those hot resultant gasses up with it. Note that we don’t really care about the fumes coming off the fire at this point, we just want as much oxygen as possible to get to the coals. If hot exhaust fumes are leaving via the same hole as the oxygen, but going the opposite direction, they will interact with each other, slow each other down, and make the furnace much more inefficient.

Also notice the hole is angled down into the base of the furnace. This isn’t by accident, we want that hole to do two things, pump air into the base of the fire, and not let anything go back up the hole. This hole in the future may contain a fan, to pump more air in. We don’t want the embers flying back up the pipe and breaking the fan during use.

To drill the hole we used a hammer drill bought from Aldi, and a 30mm masonry drill bit, these parts can be pretty cheap if you search around, and the hole doesn’t have to be this exact size. Use what you can find, and make sure you get help when doing the drilling. As always, safety is important, and safety glasses and gloves would be a good idea. if one person steadies the foundry, while the other drills, it is much easier. Go slow, so that the plaster on the inside doesn’t break too much. It is easy to be too eager and create large cracks and chips, which could mean an entire restart.

The hole from the inside
The hole from the inside, notice the dust, and broken parts around the hole.

Although this was a shorter post, the next one will be about the first tests! As always, thanks for reading, and I hope to be along with another update soon. If you guys have any tips, questions, or want to show your foundry, please post in the comments below.

Why Does NORAD Track Santa?

According to legend, on December 24th 1955, Sears department store placed an advertisement in a Colorado Springs newspaper, where they told children they could call Santa Claus with the number ME 2-6681. Allegedly one digit was misprinted, and calls came through to Colorado Springs, Continental Air Defence (CONAD) Center.

Sears Ad
The Sears Ad that supposedly started it all.

In one version of the story, the calls went through to the “red telephone” hotline that connected CONAD to command authorities at Strategic Air Command. Colonel Harry Shoup, who was a Crew Commander on duty, answered the first call. The story goes that he told his staff to give all children who called later a “current location” of Santa.

Harry Shoup, the Santa Colonel
Harry Shoup, the Santa Colonel

Another description, that is more widely believed is that on November 30th 1955 a child trying to reach Santa on the hotline number in the Sears advert, misdialed and got to Shoup at his desk at CONAD. The response was not particularly kind, and no more calls came to CONAD. Then, when a member of his staff put a picture of Santa Claus on a board tracking an unidentified aircraft that december, Shoup saw an opportunity for public relations.

He asked CONAD’s public relations officer, Col. Barney Oldfield to inform the press that CONAD was tracking Santa’s Sleigh. In the press release, he added that “CONAD, Army, Navy and Marine Air Forces will continue to track and guard Santa and his sleigh from the U.S. against possible attack from those who do not believe in Christmas”. Shoup did not intend to repeat the stunt in 1956, but Oldfield informed him that the Associated press and United Press International were awaiting reports that CONAD was tracking sta again. Shoup agreed, and the annual tradition was born.

In 1958, North America Air Defence Command (NORAD) took over reporting responsibility from CONAD. The reporting became more elaborate, with stories about santa taking rest stops, or one where Santa needed to bandage up one of the reindeer. Eventually, NORAD was renamed the North American Aerospace Defence Command in 1981, and created and published a hotline for the general public to call and get updates on Santa Claus’s progress.

Volunteers answering phone calls in 2007 of NORAD
Volunteers answering phone calls in 2007 of NORAD

Now, Norad relies on volunteers to make the program possible. In 2014, NORAD answered 100,000 phone calls, and in 2015, more than 1200 U.S. and canadian military personnel volunteered to staff the phone lines. From 1997 the program has had a major internet presence with NORADSanta.org. It also has a twitter account of @NORADsanta.

Pioneers in Aviation: The Rolls in Rolls-Royce

Charles Stewart Rolls
Charles Rolls, the co-founder of Rolls-Royce.

Rolls Royce has always been a double sided company, the luxury cars, and the aero engines. Set up by Charles Stewart Rolls, and Frederick Henry Royce, Rolls-Royce Limited was incorporated on march 1906. Starting out as a luxury car manufacturer, they quickly developed a reputation for superior engineering quality. They reportedly developed the “best car in the world”. Henry Royce had already been running an electrical and mechanical business since 1884, and built his first car, the Royce 10 in his manchester factory in 1904. He met C.S.Rolls, an owner of a car dealership, and he was impressed with the quality of the cars. A set of cars (branded rolls-royce) were made, and sold exclusively by C.S.Rolls. This started their partnership. Rolls-Royce Limited set up its first factory in Derby, after an offer of cheap electricity from the city council.

Rolls Royce Racing
Charles Rolls, sits in the back of the 20-horsepower Rolls Royce during the 1905 TT race.

Rolls could be described as a pioneer aviator. As an accomplished balloonist, he made over 170 balloon ascents. He was also a founding member of the Royal Aero Club in 1903, and was the second person in Britain to be licenced to fly by them. That same year he won the Gordon Bennett Medal for the longest single flight time. By 1907 though, he started getting interested in flying, and tried to get his then partner, Royce, to design an aero engine. With Royce not convinced, Rolls, in 1909 bought one of six Wright Flyer’s built by the short brothers. He made more than 200 flights, one of which, on the 2 June 1910, he became the first person to make a non-stop double crossing of the English channel by plane. For this 95 minute flight, he was awarded the Gold Medal of the Royal Aero Club.

Rolls flying
Rolls in the plane he flew across the channel twice in.

On 12th July 1910, Rolls was killed in an air crash at Hengistbury Airfield, Southbourne, Bournemouth. He was 32 when the tail of his Wright Flyer broke off during a display. He was the 11th person to die in an aeronautical accident, and the first ever Briton. A statue of him is in St Peter’s school which was built on the site of Hengistbury Airfield.

Death of Charles Stewart Rolls
Photograph on the front page of the Illustrated London News, 16 July 1910, showing the wreckage of the plane crash which killed Rolls

Edward Powles – Fastest Piston Pilot

Edward Powles is a fairly unknown pilot that held two rather impressive records during his time as a Spitfire pilot. He wasn’t the usual build for an RAF pilot, at 6 foot 4 inches and weighing 180lb, but joined the RAF as an apprentice during World War 2. He trained as a photo-reconnaissance pilot, and remained in service well after the war. He was trained in and mainly used twin engine aircraft. In January of 1950 he was surprised to be ordered to RAF Finningley to complete a refresher course on the Supermarine Spitfire PR14. Then on to RAF Leuchars in Scotland for familiarisation training on the Spitfire PR19, training in high and low altitude sorties.

Ted Powles
Taller than the average pilot, Ted was known as a competent and skilled pilot.

In the next august during the Malayan emergency he was posted to RAF Tengah in Singapore. His job consisted of photo-reconnaissance and ground attack missions in the Spitfire FR18, as part of Operation Firedog. This was the campaign against communist insurgents hiding in the Malayan jungle. Later in 1950 he transferred to 81 (PR) Squadron at RAF Seletar, continuing to fly medium level reconnaissance sorties over the Malayan jungle. Then just before Christmas of 1950 the CO told Powles he had been selected to take a flight of two PR19’s from RAF Seletar to RAF Kai Tak in Hong Kong on 1st Jan 1951. Powles and the other pilot, Flight Sergeant Padden, flew PS852 and PS854 fitted with split pairs of F52 cameras with 36in lenses. At this point they were not told what their duties would be, and told to await further instructions.

colour of PS852 on the ground

 

PS852 on the ground

They spent a few weeks flying sorties, assisting flights of Vampire jets being ferried into Sek Kong for Tourane. Then Powles was asked to take some aerial photographs of a number of Chinese islands in the local area by a photographic interpreter, presumably with authorisation from a higher authority. Powles would fly 63 sorties over Chinese territory during the course of 1951. During their time, the flight had photographed sites along the Chinese coastline up to 400 nautical miles to the south-west of Hong Kong, and up to 160 nautical miles to the north-east, as well as sites up to 100 nautical miles from the coast, sometimes as far as the island of Hainan. During the course of these flights, Powles set two notable records.

The PS854 likely flown by Powles, see how close his head is to the glass.

During a meteorological test flight on the 5 February 1952, Powles reached 51,550 feet in PS852, the highest altitude ever recorded for a piston-engined aircraft. He then got a cockpit pressure warning, this was partly down to the fact he was near the equator. He put his Spitfire in a shallow dive, and during the descent the aircraft quickly got into compressibility, although he didn’t know it. This locked up the controls and the plane started to dive uncontrollably, attaining 690 mph (Mach 0.96) the highest speed ever recorded for a piston-engined aircraft. He talks about putting both feet on the instrument panel and pulled back the stick with no avail. He also states he saw a mist over the wings. With very few options left, he actually pushed the stick forward, which helped to get him out of the dive. As a pilot he was experienced enough to wait until he got into denser air at lower altitudes. This gradually slowed him down, and he regained control at around 1,2000 ft over the ocean. He also put the prop in the correct pitch, which saw him through.

PS854 Photographed by Powles
PS854 Photographed by Powles, flying at 1800 ft near Aberdeen fishing village in Hong Kong

After their flight had finished, both Spitfires were left at Kai Tak and became part of the Royal Hong Kong Auxiliary Air Force. He had always thought he went supersonic, but at the time he didn’t know about compressibility. In the 1990’s he was able to show his figures to the Air and Space Museum, and they were able to establish that he went the 0.96 Mach, or 715mph.

 

 

A Trip to Bolt Tail

During our summer holiday this year, we visited Hope Cove. A lovely little village in south Devon, close to Salcombe. This tiny village, with barely a village shop used to be heavily fishing based. It also at one point in history developed a reputation for plundering wrecked ships, and smuggling.

The View Of Hope Cove
The View of Hope Cove from Bolt Tail

The reason Hope Cove is such a favourite for beach lovers is the calmness of the waters inside the cove. South Devon is known for some harsh waters and high winds on occasion, but the Cove has a lovely shelter in the form of Bolt Tail. Located to the southwest, it’s a large headland that at one point had some sort of fort located on it.

Starting at the famous lifeboat house, the south west coastal path goes up the side of the hill through a nice wooded area. It is a gentle climb, with lovely views the whole way up. Then when you get out of the woods, for the final accent, you can see why there was a fort built there.

Approaching Bolt Tail
Climbing up to Bolt Tail

Although it looks imposing, there is an easy path to get up to the top as you can see, and no iron age soldiers shooting arrows at us while we tried to walk up. From this angle you can see the earthworks built by the settlers. The straight earthwork/wall blocking off one side of the settlement (with the other three being cliffs) is known as a promontory fort. Luckily there are nice entrances now so we didnt have to scale the walls.

The wall/earthwork
The wall/earthwork protecting the settlement

As there is not much left inside Bolt Tail, and it was horrendously windy at the top, we moved on further along the coast. Its a surprisingly good walk, well signposted, and lovely views all the way around. We picked a nice day, so if it was wet, I would imagine the wind would be scary. Looking back you can see why the place was made as a fort.

Bolt Tail
The view of Bolt Tail from the top.

Along the way there were many many sheep, making all manner of sounds, sometimes they didn’t even sound like sheep! As my girlfriend said “they sound like a human pretending to be a sheep” which sounded about right. They are crazy animals as well, they were not scared to go right up to the edge of the cliffs. Much braver than we were.

There were many sheep on this trip

As it was still sunny, and we felt energetic, we continued up the hill. We eventually ended up at Bolberry down. A National Trust park, designed to be nice and flat, lots of paths around the top of the cliff, and easy access for disabled people or those with difficulty up hills. If we were to continue on, we would have passed RAF Bolt Head, an RAF base during WW2. Then right at the south of Salcombe, where the Kingsbridge Estuary hits the sea is Bolt Head. Maybe we will come back that way some day. For now, we wandered back to Hope Cove for a cream tea and a watch of the sunset.

Which Way?

Interfacing a PIC and a 16×2 LCD

So in a recent project I had to implement a 16×2 LCD  on a PIC16F1827, but the system will work on most PIC microcontrollers, with slight changes to the code. For this project I am using MPLAB X v3.40, a free development environment, and a PICKIT 3, which can be bought at a number of stores online.

Setting up the MPLAB project

  1. Start off by loading up MPLAB X, if you don’t have it already, install it from the Microchip website microchip.com/mplab/mplab-x-ide.
  2. Start a new project, by going to File->New Project… or by pressing Ctrl+Shift+Nnew project
  3. The project we want is a standalone project, it should be chosen by default. Next choose the device we want, write in the box PIC16F1827 there should only be one. We want to use the PicKit 3 for the programmer. I am using XC8 as the compiler, this is available from the Microchip to9 stawebsite. Finally choose the name of the project, and where you want to keep it. Then click finish.
  4. It wont look like mush at the moment, but under Projects on the right, there should now be your newly created project, with a drop down, and a set of folders. Something like this: 
  5. To start the project, we need a main.c. So right click on Source Files, go to New->C Main File… then in the Dialog, change the name to main. After pressing okay, it should look like this: 

Connecting the LCD

LCDs have what is known as a parallel connection. This means that we send data 8 bits at a time, rather than serial where it is one at a time. The datasheet for the PIC is found on the microchip website here. The pinout is found on page 4.

PIC pinout

Register Select (RS) pin, this decides which of the two registers that is getting written to. Either the instruction register (what the screen does) or the data register (what is shown on the screen). This is connected to A4 on the PIC.

Read/Write (RW) pin, this decides whether you are writing to or reading from the LCD. This is connected to pin A3.

Enable (E) pin, is to tell the LCD when data needs to be transferred. Pulsing this pin will write or read to the registers the data on the data pins. This is connected to pin  A2.

These pins are defined at the top of the code, to make life easier for us later on.

#define LCD_RS LATAbits.LATA4   //LCD Command/Data Control
#define LCD_RW LATAbits.LATA3   //LCD Read/Write Select
#define LCD_E LATAbits.LATA2    //LCD Enable Line

Data Pins (D0-D7), are the pins that transfer the information between the LCD and the PIC. These are connected to pins B0-B7. So B0 is connected to D0, and so on until B7 is connected to D7.

Vdd and Vss are connected to 5v and GND respectively.

Contrast (Vo) is connected to a 10k pot between the 5v  and  GND.

If the LCD you are using has connections for a backlight, follow the datasheet for instructions, on mine I connect it t0 5v and GND.

The Code

Below is the function I create to send data to the LCD.

#define LCD_CMD 0
#define LCD_TXT 1 

void LCD_DATA (unsigned char data, int type)
{
    __delay_ms(100);   // short delay

    LATB = 0x00;       // reset the register to 0
    LATB = data;       // set B output to the data we want to send
    __delay_ms(1);     // short delay for data to set

    if (type == LCD_CMD)
    {
        LCD_RS = 0;    // command mode
    }
    else
    {
        LCD_RS = 1;    // character/data mode
    }

    LCD_RW = 0;        // start the pulse
    __delay_ms(1);     // small delay
    LCD_E = 1;         // enable LCD data line
    __delay_ms(1);     // small delay
    LCD_E = 0;         // disable LCD data line
    __delay_ms(5);
}

Calling this function in the main, like follows will send data to the LCD. Notice the #define at the top, these are declaring LCD_CMD and LCD_TXT. Basically, when the type is LCD_CMD the LCD is sent into command mode, by setting the RS pin. Equally, sending LCD_TXT will clear the RS pin, putting the LCD in character mode.

The information on the data pins will then get written to the LCD, by clearing RW. To actually tell the LCD that it needs to be sent new instructions the enable pin needs to be pulsed. Once this happens, the screen should be updated with the new information.

#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

#define _XTAL_FREQ 500000

#define LCD_RS LATAbits.LATA4   //LCD Command/Data Control
#define LCD_RW LATAbits.LATA3   //LCD Read/Write Select
#define LCD_E LATAbits.LATA2    //LCD Enable Line

#define LCD_CMD 0
#define LCD_TXT 1 

void LCD_DATA (unsigned char data, int type)
{
    __delay_ms(100);   // short delay

    LATB = 0x00;       // reset the register to 0
    LATB = data;       // set B output to the data we want to send
    __delay_ms(1);     // short delay for data to set

    if (type == LCD_CMD)
    {
        LCD_RS = 0;    // command mode
    }
    else
    {
        LCD_RS = 1;    // character/data mode
    }

    LCD_RW = 0;        // start the pulse
    __delay_ms(1);     // small delay
    LCD_E = 1;         // enable LCD data line
    __delay_ms(1);     // small delay
    LCD_E = 0;         // disable LCD data line
    __delay_ms(5);
}


int main(int argc, char** argv) {
 
    // write "hello world!" on the first line
    LCD_DATA('h', LCD_TXT);
    LCD_DATA('e', LCD_TXT);
    LCD_DATA('l', LCD_TXT);
    LCD_DATA('l', LCD_TXT);
    LCD_DATA('o', LCD_TXT);
    LCD_DATA(' ', LCD_TXT);
    LCD_DATA('w', LCD_TXT);
    LCD_DATA('o', LCD_TXT);
    LCD_DATA('r', LCD_TXT);
    LCD_DATA('l', LCD_TXT);
    LCD_DATA('d', LCD_TXT);
    LCD_DATA('!', LCD_TXT);
 
    while (1)
    {
 
    }
 
 return (EXIT_SUCCESS);
}

Route Planning in C# – Setting up a Project

So after watching this video by Computerphile, I got inspired to make my own PC map solver. In the video they use Python, but I prefer C#, even if it takes a bit longer to set up and make. This Section is basically how I set up the system to import an image, turn it into a Bitmap, and then output the image to a file. Currently it is very rudimentary, and doesn’t do any mapping, but in the coming weeks, it will be improving with different algorithms and systems to integrate it into my university final year project.

This will be written similar to a tutorial, but some prior knowledge of Visual Studio and C# would be beneficial. As well as this, it is always good to read around the subject and watch videos. Experience with systems is what makes you a better engineer! For this tutorial I am using Visual Studio 2015.

  1. Open up Visual Studio, and start a new project by going to File->new->Project.
  2. On the left hand side under Visual C# choose Windows. And pick Windows Forms Application. Change the name to Route Planner (or whatever you want to call it) and pick the location you want to save the project to. Then Click OK.New project
  3. With the nice new form in front of you, drag the bottom left hand corner of the box, until it is about 750 x 450 pixels, this can be changed in the properties tab.
  4. In the properties tab, change the text value to Route Planner. The form should now have a title of Route Planner
  5. On the left hand side of the screens should be the Toolbox tab. In there find a Label. Drag this onto the form, I placed it in the bottom left corner. This will be the label we use to give us feedback on what is going on in the system.
  6. While the Label is still highlighted, go to the Properties tab, and change the name to lbl1. I also changed the text to lbl1, but this isn’t necessary.
  7. As with the label, drag a PictureBox onto the form. Make it as big as you want, it can always be changed later, but this is where the map is going to be shown as an output.
  8. in the top corner of the PictureBox is a small triangle, click on it, and change the size mode to zoom. This means that the image will be zoomed in to fit the box, as some of the images we will be using are small.
  9. While the PictureBox is still highlighted, change the name to pbMap.
  10. The box should now look similar to this:picturebox zoom mode
  11. This is the basic bit done, now to make it do something, we need an event. To start, we will set it up to do everything as soon as the program loads, in a later tutorial it will be triggered by buttons. But for now double click on the form. This should take you to a new page called form1.cs.
  12. There will now be a function in there called Form_Load() anything put in this function will be triggered as soon as the form loads up.The first look at code

The code posted below currently loads in an image, converts it to Bitmap, and then converts back to .png to save it again (under a different name).

final code

So what is going on here:

  • Firstly a new Bitmap variable is created, named startMap.
  • An image is loaded from a set filename is loaded into startMap.
  • For this project I used this image, yes it is very small:

  • The issue with leaving it at this point is that the image, although saved in a Bitmap, it’s not really one. The colours of each individual pixel are indexed in the .png format, meaning we cannot directly manipulate them, in the way we would a Bitmap. In Bitmap images, the colours are in ARGB format, meaning each colour has it’s own value, and can therefore be accessed.
  • To get the image in this format, a new Bitmap variable is created called routeMap, with the same width and height as startMap.
  • Using the Graphics class, the image from startMap is drawn onto routeMap in the new Bitmap format.
  • The pictureBox we created earlier is now used, by making it the same image as routeMap.
  • The label we created is also used, by updating the user that the file has been saved.
  • To prove it is the same image, routeMap is saved a .png file, and can be found in the directory that it is set to.

When run, and a map is named “normal.png” in the correct file directory (you can change this). The window should look something like this: Tutorial1 output

Notice how the image seems blurred, this is due to the picturebox zooming the image to fit the box. The blurring is anti-aliasing, and although slightly annoying demonstrates the image.

 

Pioneers in Aviation: William Boeing

William Boeing was an aviator with a different upbringing than what you would imagine, nothing to do with engineering or even military. Aiming to profit from the Northwest timber industry from an early age, yet he went on to create one of the biggest aerospace companies ever known, one known in almost all households.

William Boeing

Born October 1st 1881 in Detroit, Michigan to a wealthy mining engineer Wilhelm Böing and Marie M. Ortmann. From Germany and Austria. Boeing Sr had made his fortune through timber and mineral rights near Lake Superior in North America. Up until 1899 young Boeing was educated in Vevey, Switzerland, when he returned he changed his name to William Boeing. Studying at Yale University, Boeing left before graduating in 1903. Starting a new life in Grays Harbour, Washington, he aimed to profit from the lands that he had inherited from his father, who had died of Influenza in 1890. He learned the logging business on his own, eventually buying more timber land and adding more wealth to the approximately $1 million estate left to him (around £26.8 in today’s money) by his parents. This included expeditions to Alaska. One of the main reasons for his success was due to him shipping lumber to the east coast using the Panama Canal.

In 1908 he moved to Seattle, to establish the Greenwood Timber company. He started off by living in an apartment hotel, but after just a year he got elected as a member of the Highlands, a brand-new, exclusive residential suburb. During this time, Boeing was interested in boats, and often experimented with boat designs. So much so in 1910 he bought the Heath shipyard on the Duwamish River. This was so he could build a yacht, named the Taconite, after the mineral that made his father’s fortune. His love of aircraft came from a trip while in Seattle in 1909, the Alaska-Yukon-Pacific Exposition was a world’s fair publicizing development in the Pacific Northwest. Boeing was visiting as he had interests in the area. While there he saw a manned flight, and he became fascinated.

Taconite
The Taconite, the 125ft teak yaght built by Boeing

In 1910 Boeing attended an aviation meet in Los Angeles, where he tried to get a ride on a boxy biplane, he didn’t succeed. This didn’t deter him though, he took flying lessons at the Glenn L. Martin Fling School in Los Angeles, and even purchased one of his planes, a Martin TA Hydroaeroplane. James Floyd Smith, a Martin pilot travelled to Seattle to assemble Boeing’s plane and teach him how to fly it. Smith assembled the plane in a tent hanger on the shore of Lake Union, and so Boeing became a pilot. At some point, Boeing’s test pilot broke the plane enough for it to be unusable. Martin informed Boeing that the parts would take months to become available, obviously this was an inconvenience. In 1915, Boeing was introduced to Navy Lieutenant G. Conrad Westervelt, and they soon became close friends. When a mutual friend brought a Curtis-type hydroplane to Seattle later that year, they took turns flying it over lake washington. After just a few trips, Boeing and Westervelt felt that they could build a better airplane. Boeing decided to buy an old boat works on the Duwamish river in Seattle for his factory and set up shop, he was now in the aircraft business.

Boeing Plant
The Boeing Plant on the Duwamish River around 1917

Together with Westervelt they built and flew the B&W seaplane. This was an amphibious biplane that had outstanding performance compared to it’s competitors. This sealed the deal for him, and Westervelt. Together they founded Pacific Aero Products Co in 1916. Their first plane, basically the B&W Seaplane was named the Boeing Model 1. At this time, the world was in the middle of World War 1, and on April 8th 1917, the United States joined the fight. Suddenly there was a need for defence manufacturers. A month later, The name was changed from Pacific Aero Products, to the Boeing Airplane Company. The United States Navy ordered 50 planes from Boeing. When the war ended, the need for military aircraft dwindled, and Boeing started concentrating on the lucrative supply of commercial aircraft. He secured mass contracts to supply airmail, and also created a passenger airline that would later go on to become United Airlines.

B&W Seaplane
The B&W Seaplane, sitting on the water

In 1934 the Boeing company had become massive considering the time. It had an airmail business, commercial airline, manufacturing of planes and many other branches of interest. This sparked controversy in the US government, and he was accused of monopolistic practices. That year the Air Mail Act forced airplane companies to separate flight operations from the manufacturing of planes. At this point Boeing separated himself from the company, and divested himself of ownership. The company was then split into three sections. The United Aircraft Corporation a manufacturing arm, based in the east, Now United TechnologiesUnited Airlines which handled flight operations, and still functions as such, and Boeing Airplane Company which was manufacturing based in the west, this went on to become the Boeing Company that we all know today. By 1937 he had started spending most of his time breeding horses, and the new Boeing Company would not become truly successful until World War 2.

Boeing spent the remainder of his life in property development, and the breeding of thoroughbred horses. He was said to be worried about the tensions in the Pacific Northwest due to WW2. This led him to purchase a 650 acre farm east of Seattle. He called it “Aldarra”. He would go on to die September 28th, 1956 at the age of 74 (a year before the release of the release of the 707). He died of a heart attack while on his yacht. His estate was eventually sold off and turned into a golf course in 2001, but parts still remain today, including Boeing’s main home, and two smaller houses. His house in the Highlands was also listed on the National Register of Historic Places. Also a creek running near his house in the Highlands was renamed Boeing Creek after him.

Boeing Creek
The Creek named after Boeing, running near his house in the Highlands