Skip navigation

Some fun news first, We now have a logo for the "Company" (as this is a mock project, its a mock company). We are Called Alpha Vending Solutions


I have just managed to get working the Maintenance mode Software using visual c#. The fix to get the serial port object to work was annoyingly simple once I found it.

The main use of this software will be to test functionality of the system, Send servo commands, read sensors and such. As we still are not fully sure on what software we will need, it has been made as a MDI (Multiple Document Interface) to allow more forms and controls to be added as needed.

The fix i found for getting the serial ports to work over multiple forms was to pass the Serial Port which has been opened in the main form to the other forms as an argument, see bellow

On the Form to be opened


using System.IO.Ports;
SerialPort serial = new SerialPort();
public Servo(SerialPort port)
            serial = port;

On the Main Form

using System.IO.Ports;
SerialPort sp = new SerialPort();
private void servoToolStripMenuItem_Click(object sender, EventArgs e)
            Servo SVR = new Servo(sp)
                MdiParent = this



So in the main form 'sp' is opened with the required com port, using the menu. Then it is passed to the other forms when they are opened, and set to another serial port object. So far this solution is working for me and i hope to keep it that way.


The only issue I can see being with this, is that it requires me to use the readline() and Writeline() method in every form and have the required exception handling every time. although after the trouble I had trying to get this to work in the first place, i really don't mind having the extra work. I could also see an error happening if you open the form before opening the Com port.


This afternoon we will be interfacing the MBed with the software to read the colour sensor and display the results, and i will be sitting down with the mechanical design team to work out the state machine i will need to implement on the FPGA. Ill try and post about them as well

For the Digital Design (FPGA) aspect of the project we need the system to take inputs from the Mbed. Mostly it will be controlling Servos in a finite state machine, but when the system is in maintenance mode it needs to control the servos individually. This has lead me to come up with  a quick block diagram of how the system should operate.


It will take the inputs via UART, the commands are then decoded (not shown) and sent to the relevant module. Both modules will output the to the same servo modules. This means that a buffer will probably be implemented on the maintenance mode outputs to force them high impedance during FSM operation. I am lucky in the fact that the FPGA board which we are provided with already has a UART Module on it, so I will not need to worry about writing one in verilog, i will just need to write the decoder.



As for the servos Drivers they are complete and have been tested via an oscilloscope. I would have tested with a servo attached, but it would appear that the IO Buffers on the board are busted and so the max output voltage is currently 66mV and i will be talking to the lab technician about fixing/ replacing it. This is why the Signals bellow are so noisy, just due to a cheap scope and low voltages ( i am hopping)


the images are not as clear as i would like and the software for my scope did not include the measurements of the period, and pulse width.

to Summarize the images, the first is a zero input to the servo module, which is producing a pulse width of approx 1ms.

the second is 255(Max) sent to the servo module, and is producing a pulse approx 2ms wide. So it works, apart from the low voltage, What i will probably try is an IO Port on a different buffer see if that fixes the issue. If you are interested in The Verilog Servo MOdule i have a write up here Verilog PWM

Just a quick update on the project. The initial mechanical design has been completed by my team members, and once they explain it to me; I can explain it here. As right now their scribbles make no sense to me.


A couple members of the team are beginning to work on reading sensor data via the MBed, and failing miserably. I am starting to notice a pattern in the source code examples our lecture is giving up, they are (for lack of a better work) crap. If you don't know what i am refering to check my previous blog post on the Verilog PWM assignment we had to to for the course here Verilog PWM.


Since the MBEd will just be a passthrough for serial command, I decided that i will do the maintenance mode software; using C#. As once the main bulk of the FPGA Design is completed, I will just need to wait on mechanical design being completed before I can design the state machine to operate the system.


The main idea is to have the main form as an MDI, Multiple Document Interface, as you see some DEvelopment environments. This gives us the opportunity to just design more forms and add functionality as we need it. Just one big problem, it would seam that C# and Serial Ports hate me just now. I have tried using the example code given to me by my lecturer, but it doesn't do what I am looking for. I have looked online and when i try to duplicate, it does nothing.


Let me explain a little;

as I am using a MDI which means that several forms will be either sending serial data out, or receiving it. I am looking to set up a public function in the main form which watches the serial port and then returns the value. This way any other form can call the function to watch the serial port, without having to set it up in every form. yet no matter how i try to do this it either throws a runtime error at me, or just does nothing. I am testing it by having two FTDI chips connected to each other and to my computer(and before anyone asks, my connections are working and have checked them using a serial terminal).


If anyone has any ideas on how i can accomplish this, or know someone that does; please help. I'm running out of hair to pull out.

Im currently studying my third year Electrical and Electronics Engineering at Heriot Watt University. This semester we have a Project to complete as part of a team of fellow EEE students and Computing Students, and i though i would let the community know about it.


The majority of the project is technical, but we also have to look at it from a project management aspect, i will leave out the project management side to be nice. I will mostly be doing the digital design aspect of the project, but will most likely be helping out with the other aspects of the project, i will try and upload as frequently as i can. I will welcome any comments, or suggestions which you have.


Here is the specification that we were given

Project Background

Sensing is key to many autonomous systems and this project will be making extensive use of a variety of sensors to develop a system that can operate with a level of autonomy

Design ability is one of the key objectives of the engineering process. A successful design requires the application of a combination of creativity, skill, and the ability to analyse and synthesise.

The purpose of this design project is to provide an opportunity for these abilities, which you have begun to acquire in the first, second and third years of the course, to be exercised in conditions similar to those under which engineers work in industry.

Many industrial products and processes use a combination of computing, and embedded software and digital technologies applied to some physical system, the design project contains elements of each. This project is structured to give you experience of designing across artificial disciplinary boundaries, its successful completion requires you to exercise system integration skills.


Snack-O-Mat is a newly formed company to produce intelligent solutions for sensor based snack systems. Their business model is to manage the design, delivery and maintenance of the automated equipment for a robotic supply system. However, they outsource the technical development of the equipment to 3rd party electro-mechanical design companies.

Their first project is with a company that runs a snack supply system that reads a card to indicate known allergies and automatically dispenses the required number of snacks to a user. They have specified the need for an automated analysis system to sort out the snacks which contain particular allergens.The analysis will be done (in a similar what to spectroscopy) by looking and the different colours present in the presented sample.

The company has contracted Snack-O-mat to design and deliver an automated system that will work in conjunction with the user to supply the required snacks.

A set of companies have been asked to bid for the contract by building and demonstrating a proof-of-concept unit. The final decision on which company gets the contract will be based on a public competition to be run in December 2017. At this event, each machine will be demonstrated and supported by the submission of a suitable technical document.


    • 1. Design and build a small system that reads a user's card indicating what allergies the user has and gets an input from the user indicating how many snacks they require. The system reads the colours on the snacks to defines which allergens they contain. Then the allergen free snacks are to be dispensed. The system must ensure that the user is present whilst using the analysis system, but they must be at least 10cm from the machine. Upon analysis the required set of snacks should be dispensed automatically to the user.
    • 2. The system should indicate if it was unable to fulfill the required action, i.e. if it does not have an adequate supply of snacks or there is some other issue
    • 3. Once started, the machine is to run without operator intervention. It should however, interact with the user through the PC interface and any appropriate LED indicators to show the user what is happening, whilst ensuring the user remains present, but is not too close.
    • 4. A connected PC will allow initial setup of working parameters and show progress of the machine
    • 5. The system should have TWO distinct MODES.
      1. • Operate mode
      2. • Maintenance mode
    • 6. Operate mode is the normal mode with the machine selecting blocks of a specific size and checking the colour of the selected snacks.

    • 7. The maintenance mode allows an engineer to test and diagnose any machine problems.

    • 8. A PC computer will provide the following
      1. • Operate mode
        1. • Monitor progress and display appropriate data on screen
        2. • Maintain simple database of snacks that have been analyzed and those needing reprocessed.
        3. • Tell the operator, through a speech facility, what the machine is doing. This facility to be switchable between English and another language (e.g. French, Chinese, etc.)
        4. • Show result of the snacks that have been analyzed for allergens and the appropriate snacks dispensed.
      2. • Maintenance mode
        1. • Provide a facility to test the different aspects of the machine for maintenance purposes.
        2. • Move servo motors
        3. • Read sensors
        4. • Provide suitable GUI interface to run the maintenance commands
    • 8. The Altera Cyclone FPGA system
      1. • Operate mode
        1. • Once a GO signal has been received, the FPGA unit will control all aspects of the actual snack sorting process
        2. • Show some simple information on the FPGA board displays
      2. • Maintenance mode
        1. • Receive commands from the MBED unit
        2. • Send command to FPGA
        3. • Move servos and motors
    • 9. MBED unit
      1. • Operate mode
        1. • Communicate with the PC
          1. • Generate “go” command to FPGA
          2. • Read monitoring sensors and send to PC
      2. • Maintenance
        1. • Communicate with the PC
          1. • Read commands from the PC
          2. • Execute these commands and return data to the PC
          3. • Read sensors and return data to the PC
    • 10. A card will identify the users' allergies. The user will then enter into the system the number of snacks required. The snacks will not be loaded into the system already sorted for allergens, but they will be stored together. The system will test each snack for allergens. The dispenser will indicate if it is unable to fulfill the required action, i.e. there when it runs out of suitable snacks in the machine. The user card will be the size of a credit card with FOUR notch areas, which can be filled, or cut-out. This would give 16 possible combinations.
    • Code numberAllergy (colour)
      0000No allergy

    1. Insertion of the card will prompt a set of activities
      1. • Read card code
      2. • Check code against central data file and indicate any allergy issues.
      3. • Request entry of the number of snacks required
      4. • Check that machine can satisfy order
      5. • Indicate problem if machine has insufficient snacks
      6. • Dispense snacks if all is OK.
      7. • Prompt for user to collect snacks and card
  • 11. Sorter to fit onto a 300mm by 300 mm baseboard. Height to be less that 500mm.
  • 12. Teams may add additional features after agreement with the project manager.
Duncan Fraser

Hantek 6022BL

Posted by Duncan Fraser Oct 6, 2017

So I ordered myself a Hantek 6022BL this week, as I have wanted an oscilloscope since i started tinkering with electronics. Since I am a student though, a couple hundred pounds is a lot of drinking money to spend on one item, especially since knowing myself I would most likely blow it up at some point as I don't have much experience with them. Not going to be a full review, just my first reaction upon playing with it this evening.


I was watching Dave Jones (EEVBlog) video on starting an electronics lab on the cheap, and he mention this one, although he did go on to say to get the other one as it has USB Isolation. So for £65 off amazon i thought why not, the specifications seem fair enough for the type of hobby electronics I do.

2 Channels , 20Mhz Bandwidth, 48MSa/s sample rate and a 1M memory depth, along with a 16 channel logic analyser.


The first thing that surprised me was how solid everything felt, Aluminum case, descent feeling probes.

the one part i did not like about the case was the rubber feet that surround the case. Having them in place make it annoying to attach CH1 bnc and trying to get to the pulse out pins, they are a bit difficult to remove and try to take the labels with them as well. The only other thing i can see annoying me when using this is the ribbon cables and connectors for the logic analyser. As they just use normal headers to attach the clips to the ribbon cable, they feel rather flimsy and I will probably take the effort in the future to make these a more solid connection.


It was really easy to set up. Install the current software from hantek website, install the drivers (download from website) and it's ready to go. Adjusting the compensation the probes was easy enough when reading through the manual.

So far the Software is easy enough to use and get to grips with. I haven't looked through the software much more than fiddling with a couple of the controls.


I think that this oscilloscope will be great for me to grasp the basics of using oscilloscopes and for the price i payed I am not bothered if it doesn't last a lifetime or if it is sometimes off in measuring; but i think i would recommend it as such to anyone looking into getting their first oscilloscope.

Duncan Fraser

Verilog PWM

Posted by Duncan Fraser Oct 5, 2017

For an Assignment for university my class had to write a verilog program to produce a PWM output derived from the ASCII Value of our initials which can drive a servo.

We were provided a sample verilog source from fpgas for fun, which was clear as mud, but did produce the required output. All examples a could find online where for a simpler PWM output, ie with a period the same size as the largest value of the pulse. Which is more suited for constructing a analog output.


So I have gone through the source provided and found what i considered an acceptable explanation, from which I taught a several of my classmates who where struggling. I though I would put it up here for everyone to see, I hope it is of some use to someone. And apologies for poorly drawn graphs.


For producing a Servo signal we need pulses between 1ms and 2ms with a frequency of between 50Hz - 100Hz


As we want to module to accept a 8-bit number to determine the pulse width, in the case of my assignment an ASCII Character, we need to divide the variation by the number of steps you can have in a 8-bit value.


1ms/256 steps = 3.9us per step


Therefore we need to generate a clock with period 3.9us from which we will work from to produce the outputs.

For this we take the frequency of the input clock, in this case 50MHz, multiply it by the time variation and divide by the number of steps in that variation.


(50e^(6) x 1e^(-3))/256 ~= 195


This is the value we will use to generate a saw tooth wave which will allow us to generate the clock of period 3.9us

A counter will be incremented on each 50MHZ clock edge, when this counter reaches 195; we generate a pulse on clkTick and reset the counter. This looping is what will generate the 3.9us clock



To generate the period between the pulses we will use a second saw tooth counter which will use the 3.9us clock to increment it.

To calculate the size of this counter we need to use the desired period of the output


log2(output period/clock period) = log2(16ms/3.9us) = log2(4109) ~= 12-bits


16ms was used as it gives a value closest to a whole bit. This counter will be incremented every 3.9us clock pulse so we have approximately 16ms between pulses, and will be allowed to roll over to zero when it maximum value is reached.


To generate the output pulse into we first need to take the input 8-bit and add a 4-bit binary 1 onto the front, this is done using condensation operator (can't remember actual name)


     {4'b0001, Input}

this produces a 12-bit output with a minimum value of 256 and max of  511, which when multiplied by 3.9us give us 1ms and 2ms respectively. To do this in the code, we set the output high when this number is less than the current value of the 12-bit counter.

So by giving the input a value between 0 and 255 we can produce servo pulses between 1ms and 2ms with and variation of 3.9us.


I have included below my verilog source for my assignment, which includes some extra case statements for changing between upper and lower case, and for counting the output pulse to change the value after two. I will also add the original source from fpga for fun, and you will see what i mean by mud, no disrespect to the author.


I hope someone find this useful, or just interesting, please let me know your thought in the comments