Saturday, 3 June 2017

First Year Engineering -- Year in Review

It's been quite a while since my last post, and that shouldn't really be a surprise given the rat race of final assignments and exams of my first year at the University of Windsor. It's over now though. Only two classes during the summer session to get ahead and make my life easier next semester (albeit the two hardest pure math courses required of engineering students at my school).

So what do I think of school so far? To be honest it's hard to make a clear judgement from the first year alone. Since my school employs a first year "general engineering" curriculum it was hard to get excited for studying things that would almost go into the waste bin the moment I hand in my final exam. Though I won't be using fluid dynamics or statics during the rest of my education, there were still valuable concepts we learned that are general and broad enough to transfer to all aspects of engineering, which I appreciate. However it would have been nice if I could get right into the electronics theory and physics while learning those same general concepts as in fluid dynamics and statics. I understand why the school has this type of curriculum, for those students who don't really know what they want to get into, but I've already been through an electronics technology program and it would have been nice if I could have tailored my first year a bit more to what I want. Regardless, I got very good grades and I still took something away from every class, and I think if you complain about that you're just making a fuss out of nothing.

My school definitely seems to be more tailored towards mechanical engineering though. You would think that for a year where you give all the students a taste of what could lie ahead you would include SOME form of electronics. As previously stated I did not need any sample of that sort, but I feel like a lot of my classmates could really get engaged with electronics. Unfortunately for the most part the opportunity just wasn't there. I've actually joined the IEEE student branch recently and I might be volunteering to make some presentations on these sorts of topics to get students engaged in learning outside of the classroom. I've heard stories about students in the later years of their education being nearly clueless about some pretty basic practical concepts that I could definitely help with, so we'll see how that goes.

In case you're wondering, no. No there is no way I would not include electronics in my "general" classes. One course we took was called "Technical Communications" and was basically all about proper use of e-mail, workplace etiquette etc etc. It was one of those classes with the dreaded final group project worth 30% of your mark. Luckily, when our professor announced the project to us, she revealed that we would be building something with Lego. Programmable Lego. Bingo, jackpot, hallelujah. A marriage of my childhood toy and my young-adulthood toy. (this was the Lego kit we were given). She stated that the project was primarily a writing assignment due to the massive product proposal document, so I was a little bummed out. On top of that, the subject of what we were building was "something that could teach somebody something" which I find rather limiting and kinda lame but no big deal. We would come up with something neat either way.

Fast forward a bit and our group ended up going with a robot that could teach a child basic colours. We would have the robot feed a gumball from a hopper into a colour sensing compartment where the colour would be identified and the gumball would be dispensed into its colour-sorted pile. We would have liked to have some kind of remote input from the user that would make the learning process more engaging but that was a lot of work and this was "primarily a writing assignment". Unfortunately, there was a lot of studying to be done and a lot of other assignments so we did not go that far. However, the Lego kit did not come with a colour sensor, but I reassured my team that we had a hidden super power: a geek with an electronics fabrication lab in his room.

Thus the design process of a colour sensor began. First I had to figure out how conventional colour sensors work, and of course there is a selection of integrated circuits that handle the raw colour sensing part. I ended up choosing the TCS3200 as it had an easily manageable package and had a relatively basic order of operations. The chip contains an array of different photodiodes filtered for red, green, blue and clear (for light intensity). Basically, when a photon with enough energy hits the photodiode, it causes an electron in the connected circuit to move. Using this principle, when the chip is under a light source, a certain amount of current is produced proportional to the amount of light that enters the chip. So, if I shine a red light on the chip and select the red filtered photodiodes (by use of one of the pins on the chip), a current proportional to the intensity of red light is used to drive a variable frequency driver, and a pulsed-square wave with a frequency proportional to the current (and thus, light intensity) is output on the chips output pin (sorry if that's a little wordy, it's the shortest and most descriptive way I could put it). All that has to be done to detect the actual colour is measure which frequency (intensity) for each RGB colour the chip is exposed to, and the colour can be determined.

In order to realise this design, several functions would have to be covered. 3 white LEDs were used to act as a light source that would shine light on the gumball, and the reflected light would contain the same wavelengths of light that we see when we look at the gumball (since we usually have white light as a light source in daily life). Next, a microcontroller was used to count the pulses output from the TCS3200 over a predefined span of time (0.25 sec) to calculate the frequency of the selected colour which was also selected by I/O pins on the microcontroller. Other than the colour sensor itself, there needed to be a communication link between the Lego brain box and the colour sensor. Through much research, it was clear the best method was to use the I2C protocol (pronounced "I - squared - C"). I won't get too into it here, because it's a rather lengthy subject, but for those that are interested the Wikipedia page offers a good introduction. Basically it offers a serial communication protocol for a master-slave hierarchy. The master device (Lego brain box) selects which slave device (colour sensor) to communicate with and requests a certain amount of data that the slave will then send back. It's a very robust protocol and it's actually used very widely in many industry applications including all the accelerometers and gyroscopes in smartphones.

I designed the PCB in the Altium deign suite that I believe I mentioned in a previous post, so go check that out for more of my thoughts on it. This time however, I went for the whole nine yards and developed a 3D model of the circuit with all the bells and whistles. Very satisfying to say the least. Here's a screenshot of what you can do in Altium extremely quickly and efficiently:

                                        

As you can see, it's a fairly basic PCB (with the connector on the right-side missing since I had to modify the placement at the time of taking this screenshot). The 3 white bulbs are the LED's with the black chip in the center being the TCS3200. In reality the chip is clear but what was important for the model was the geometry of course. The other black chip is the PIC16F1503 microcontroller used to count the output frequency from the TCS3200 and act as the slave device in the I2C circuit.

I also designed a Lego-style enclosure for the colour sensor so we could easily mount it to our robot in the classic Lego fashion. Here's some images of the model and my CNC machine milling out the parts.

                                     

On the left is the assembly exploded and on the right is the assembled sensor. Here it's obvious how useful Altium really is. I can easily export the model created in the software suite (the purple-shaded piece you see in the middle of the assembly), and use it in my CAD programs as an exact reference to what the assembled circuit will be. Absolutely brilliant.

                                                     

This is my CNC machine milling out the parts.



This is the PCB which was also milled on my machine. Here I have't yet finished the fabrication, as I accidentally broke a leg off the fragile TCS3200 and had to order a new one, but it illustrates what the real circuit looks like

                                                 

The completed circuit in the enclosure. It turned out really well and worked just fine with some calibration and quick programming.

                                

Some images of the assembled robot. Looks like a mess and that's because it kind of was. We needed a motor to drive the robot back and forth, one to drive the feeding mechanism, and one to actuate the dispensing mechanism. The entire robot needed to have a small footprint so we decided to build vertically. It ended up functioning as planned and we had a really great presentation.

Since there were so many groups that had to present, by the time we went up it was more of a "lets get this over with" for the entire class and professor (especially due to some of the robots we saw.... which I wont get into). I don't think I got the point across of how much work I put into designing the colour sensor, as even the professor said at the beginning of the course that this was primarily about writing so I didn't really get into it, but all the recognition I needed to feel accomplished with what I did comes from the satisfaction of actually doing it. I learned a lot while building the colour sensor and programming the robot, and at the end of the course I felt I made it at least ten times more valuable than "just a writing class".

So my first year went pretty well. I learned a lot both in and our of class. If I continue at the pace that I'm going at now, who knows what will be possible by the time I graduate.

This post has ended up being extremely lengthy, so I'm going to end it here. If anyone wants more details, feel free to comment. Thanks for reading.


Tuesday, 21 February 2017

3 Axis CNC Milling Machine



To finish off the program I took at St.Clair College I was required to create a final "capstone" project that would display the things I have learned over the 3 year period. Since I got a job as a CNC machinist half way through the course, it was obvious that a CNC machine would be a good idea. Little did I know at the time that this project would spark the passion for electronics that motivates me to this day.

CNC stands for "Computer Numerical Control". When you slap a "CNC" onto a set of motors, linear axes and a cutting tool (called a spindle), you get a CNC milling machine. CNC mills are useful because they allow you to machine parts with complex geometry at extremely high accuracy and speed. Check out this video for an incredible demonstration of a ridiculously expensive German built CNC machine manufacturing a demo part. Obviously my CNC will be orders of magnitude simpler than this one, as I don't have $3 million to spend.

At the college we had learned quite a bit of circuit theory. From DC to AC circuits, and some digital and programming as well. My understanding of how I could build the electronics to control a CNC machine was strong in its foundations, but I was clueless on the best way to go about starting. Thankfully google is a good friend, and it wasn't long before I discovered LinuxCNC. From forum posts to wiki articles, I was able to construct a basic block diagram of how a generic CNC machine works:


LinuxCNC does most of the dirty work. It understands the G-Code language that machining programs are written in, calculates the required control signals to move the axes into the correct XYZ positions, and sends these signals over a basic DB-25 parallel printer port. My job was to build a stepper motor driver circuit and make sure that all it needed was the inputs from the PC.

To get started I just googled "stepper motor driver". Little did I know at the time engineers design integrated circuits for just about bloody everything. The magnificent Texas Instruments DRV8825 caught my attention immediately. Here we have a single 28-pin chip that drives one bipolar stepper motor using no more than "step" and "direction" signals. It it literally the perfect solution. All my driver would need is three of these chips along with a voltage regulator to step down the motor supply (24V DC) to a logic level (5V DC) to power some signal buffers.

I will skip over all the headaches I went through in the design process as this was my first official, ground-up circuit design project. The following is the final circuit board (with a fancy heat sink that I ripped off an old PC motherboard):


The 3 motors connect on the left side of the circuit, power goes in to the top, a motor enable switch goes in the bottom and the DB-25 cable from the PC connects to the right.

This circuit was milled on an industrial CNC mill at work during some downtime, but later on I redesigned the board (with some upgrades like a DC-DC buck converter instead of an LDO) and sent the design out to a production company based in China named SeeedStudio. Their price was unbeatable (as expected) and their quality is well within tolerance. I send them the design, they send me back the unpopulated board. This is the final board in its working state:


(I will soon be adding a sidebar gadget that I will throw all my schematics in for anyone that is interested.)

So now I have a working stepper motor driver. Next up is to get the actual machine structure and spindle. Since this is essentially an electronics project, I decided to go with good ol' ebay.

I browsed auctions for a few weeks, and eventually found a really sweet deal. It had an aluminum construction, and my favourite part: ball screws. The best part was that the entire price of the aluminum and ball screws together was about the price of any other set of ball screws I could find. Here she is:


There are a few quirks and bad design decisions embedded in this thing, but for what its worth I don't mind. For example, the spindle hangs way off the front of the x-axis (left and right from picture view). When you put axial load on the spindle (z-axis), the machine experiences a lot of flex due to the spindle mount applying a high torque to the support rails (torque at a point is proportional to the force applied at the perpendicular distance from the point of interest). Another issue which coincides with the previous one, is the spindle is not aligned with the y-axis ball nut, so at maximum y-axis stroke the spindle either hangs off the end of the table, or doesn't make it all the way to the back. I could continue pointing out the mind-numbingly bad decisions here but I don't want to depress myself too much (I plan on redesigning and building the body using only the ball screws from this machine).

Along with the body I ordered a brushless DC spindle motor. The motor came with a drive but I ended up building a (slightly) faulty driver circuit that I ended up having to put off for more important things. Due to the complexity of the circuit, that's a topic for another day. This is the motor I purchased:


At this point the machine was fully functional. I was programming machining programs on my personal desktop and usb-keying the programs over to the Linux PC. Here are a few things I machined out of wood:

Actually the first thing I machined, a shell made out of hard maple:

How about a lizard?

An Elephant?

Now obviously these are all just for-fun projects. The cool stuff came when I started milling circuit boards to improve the functionality and convenience of the machine.

First off, I made a handwheel. Handwheels on CNC machines are used to manually move the axes for part setups. You may wonder, "Okay, I have a piece of wood on my CNC machine, now how does the machine know where it is?" Generally whenever you are setting up a workpiece, you want it to be square to an axis. So, you throw a dial indicator in the spindle and indicate a surface on the workpiece. If you have the same reading on the indicator on one side of the workpiece as you do the other, then the workpiece is aligned to that axis. After that you can manually tell the machine that it is at position X0.0 Y0.0 Z0.0, or "home". Handwheels make this very convenient. I can select the axis of motion, the speed of motion and turn a rotary encoder to index the axis in the direction of rotation. On my handwheel, I took some designs from the fancy machines I use at work to help make life easier. There is a "deadman" switch that has to be pressed in order for the machine to move, as well as a button that sets the current axis position to 0.0 for orientation. I will skip a lot of detail for the sake of brevity, but here is the circuit for the handwheel (which was milled on this CNC machine!):


You may wonder why the circuit has an odd shape, and that's because I also designed an enclosure for the circuit to sit in. Using the same techniques I use at work on the weekends, this is what I came up with:


There are 6 holes for the push buttons used for selecting the axis of movement and speed, the square hole is for the "homing" button that sets the position of the current axis to 0.0", there is a little wheel that will be friction coupled to the shaft of the rotary encoder and there is a mounting hole at the top right that you can use to hang the handwheel on something. I use a standard bolt driven into the side of my table. I ended up machining the handwheel out of a machinable plastic called Renboard which is commonly used for prototyping. The final product (again, milled on my machine):


On the left is the final product, hanging off my table, and on the right is a still from when I was machining the inside compartment where the circuit goes.

Next up on my list was an RPM sensor. This would be a simple circuit that would display the speed of the spindle motor on some 7-segment displays. The circuit works by using a counter that is triggered by the shaft of the motor passing by a hall-effect sensor. Every quarter second the count is taken, multiplied by 240 (0.25*4 = 1sec * 60 = 1min) and the result is displayed on the 5-digit 7 segment display I designed (the spindle ranges from 0-14000 RPM). Being so simple I was able to whip this circuit up in a couple hours on a breadboard. Within a week I had the working circuit:


For the last circuit, I wanted to make a "motherboard". This circuit would connect all the pieces together, act as a common ground point, add some GPIO, and some safety circuits like an E-stop and Power enable switches. Pretty simple design really. It didn't take that long to make, however for some reason I made it very large. I don't know why, I must have not been thinking too much that week. Anyways, here's an image of the circuit:


Actually I lied. The LAST circuit was a small LED module that I plugged into some of the GPIO I had made room for on the circuit (those 8 open holes on the south-side of the board). This module is basically just an LED driver I can use to indicate which power/e-stop states the machine is in. This is the circuit:


To finish the project off, I had to come up with some way of housing all the components. I decided on using some plain old MDF boards from home depot that I could machine into the desired shape on my CNC. This is an image of what all the components looked like prior to the housing:


Fans and cabled all over the place, two mains plugs, and a large footprint. The following is an early 3D model of the enclosure and the finished product:



I kinda messed up on the button labels, as the text got messed up in some spots, but overall I was pretty happy with it. It served the exact function I needed it to and posed no risk to the circuitry inside.

So there it is. A fairly brief walkthrough on my CNC project. If you're wondering how it was received by my fellow students and faculty, it was absolutely awesome. I presented my project on the last day of a 2 week presentation process and without fluffing my own feathers too much, it was a great way to end the presentations. I had unintentionally went like 20 minutes over time while still spewing information a break neck speeds just because there was so much detail in the project. I think my professors were enjoying it though so nobody said a word. A few nights before I had spent some time making a video showcasing the CNC in action. When I showed this video the entire class and faculty was in an uproar of laughter right from the beginning. Let's just say there are a few inside jokes in the video. The most obvious of which is the still image of a faculty member that pops up randomly. Oh the memories of that day. By far the presentation alone made every headache and late night worth it. Words really can't explain how much this project meant for me at the time and still does to this day.

Feel free to comment or ask me for details, schematics, layouts etc.

Sunday, 19 February 2017

Projects and Ideas Currently In the Works...

Just to put some direction to where this blog will be going in the near future, here are some of my current ideas and projects in the making:

- Oldschool Z80 microcomputer.

I took a course at St.Clair College about microprocessors and we had the pleasure of programming some old intel 8085 CPUs. I know it may sound lame to those that are fiddling with the most bleeding edge development boards and whatnot, but to manipulate silicon the way that the first digital electronics engineers did has tremendous value to me. My theory on learning complex things is that the best way to truly understand how something works is do figure it all out for yourself. Sure you can just read some guy's tutorial on how to do X, Y or Z but if you develop the method yourself the knowledge will be extremely concrete. Unfortunately this theory is dying now that I am in University and I see that there is just way too much information out there to develop on your own. Hence; the Z80 computer conundrum.

I decided to start building a 1970's computer in order to truly understand computer architecture. I read and re-read the Z80 CPU datasheet countless times slowly generating a block diagram of how the whole thing would work. Eventually I came up with a design that I was sort-of confident in, so I visited my old friend Digikey.ca, broke out the bread boards and started plugging away.

To my surprise, the design worked on the first go! Besides some almost inevitable quirks in the breadboards which I had to meticulously phase out, I was able to read the state of some dip switches, and copy their states to some D-Latch Output registers that were connected to LEDs. That may not sound like a computer to the uninitiated, but trust me, that simple test circuit displayed the fundamental workings of how you are able to read this right now.

Once I saw my design was functional I wanted to be rid of the god awful breadboards as soon as possible. I typically use EagleCAD to design my PCB's (printed circuit boards) but since I am getting a formal engineering education I decided I might as well learn the industry standard software. Long story short, I got my hands on a copy of Altium Designer and started developing the PCB. The design is complete now but here's the conundrum part:

Am I wasting my time? Today you can buy a $5.00 microcontroller that has everything this Z80 computer will have plus 30 other things and it operates at 10 times (at least) the processing speed . Perhaps my theory on learning the barebone fundamentals is slowing down what I could be learning instead. Due to this internal battle, I have put this project on hold. I will return to it at some point, as I already have all the components, designs and the means to manufacture the circuit in less than a couple hours.

Surrogate Project: 0.75KW 3-Phase Induction Motor Driver using Lead Acid Batteries and Inverter Circuits

My place of employment recently threw out a bunch of old computer parts and junk that was laying around. Included in this pile of gold were some UPS (uninterruptible power supply) units. These basically take the DC voltage from lead acid batteries and put them through inverter circuits to convert the DC to AC and step it up to mains voltage (110VAC in Canada). Being deeply involved with electromechanics practically all the time, I decided to marry the idea of the UPS inverter circuits and a 3phase motor I picked up at an auction a while back. Ultimately I would like to be able to strap my drive circuit and motor on a homemade gokart chassis and zip around using essentially a car battery as the power supply. This project is still in its very early stages, since I'm so busy with school and all, but I already have a very good idea on how it's all going to work. I found this fantastic project document from some students at the Worcester Polytechnic Institute which outlines how sine-wave inverters work in amazing detail. All I really have to do is figure out how to get 3 sine-wave outputs offset 120 degrees from each other with varying frequency. The circuit design shouldn't be too difficult, but I can sense that to get a practically-working-non-exploding model will be difficult. Safety equipment definitely required!

There are a few more things I have going on in the background but this post is getting lengthy enough as it is. Stay tuned in the near future for some more detail on my past projects and the current progression of the ones listed in this post.



Intro to Sousa's Lab

To start off, how about a small Bio.

My name is Connor Sousa and I'm currently a 22 year old ECE student at the University of Windsor. On the weekends I work as a CNC machinist in the plastic injection molding industry (we do most of our work for automotive companies).

As you may imagine, I have an excruciatingly busy schedule being a full time student and a full time weekend-shifter. Due to this fact my projects will likely move along very slowly during the school year and kick into high gear during the summer.

A bit of a project history:

- I've made 9 (I think?) traditional style bows with primitive tools. From chopping down a tree limb with an axe or saw to shaping and tillering with woodrasps and chisels. I will probably upload some images at some point.

- A series of small electronics projects during my education at St.Clair College in Electronics Engineering Technology

- Probably the project I've put the most work into is my CNC mill. It's a 3-axis milling machine made out of an aluminum body that I purchased on ebay and the control electronics that I designed myself. The controller is a PC running debian linux and a software package called LinuxCNC that talks to my control electronics over a parallel port. To avoid going into detail here, I will be making a post shortly outlining the project and my design/build process in detail.

I think it's safe to say I've taken more things apart and salvaged their sweet juicy vitals than I have built things from the ground up. Let's just say I have a couple shelves filled with parts that could build me a nice spaceship (only slightly exaggerating).

As I previously alluded to earlier, I will be posting some details on the projects I listed above at a later point. Study week is about to begin and I plan to squeeze every last drop of free time out of it to get ahead on my courses.