недеља, 26. новембар 2017.

Custom made 16-bit CPU

I have created a custom made 16-bit CPU. I have used the LogiSim tool to create it. The CPU has three registers (A, B, and C), PC, SP, and some internal registers, such as MBR (Memory Buffer Register), IR (Instruction Register), and HIGH-BYTE register (keeps the upper 16-bit word of the  32-bit multiplication result, or a remainder when doing division).
Besides CPU, the system has 2x64KB of RAM and 16 words of text-based video memory, starting from the 0xfff0 address, and going to the 0xffff. The ALU is capable of doing all important operations including hardware-implemented multiplication and division. Both multiplication and division consume 32 cycles for 16-bit operands.


All the microcode is placed in two 32-bit ROMs:

There are around 100 instructions implemented: load/store, arithmetic, logical, shifting, jumps, calls, etc.
The CPU project is placed at the github: https://github.com/milanvidakovic/16-bit-CPU
The assembler for this CPU was forked from the original custom assembler and is also on the github: https://github.com/milanvidakovic/customasm
The output of the assembler are files in a such format that the LogiSim can load them into the RAM memory component.
The emulator was written in Java and it is capable of executing the machine code instructions which are the output of the assembler. It is also on the github:
https://github.com/milanvidakovic/16-bit-CPU-emulator

I have also created a transsembler which converts x86 assembler code made by the MS C compiler into the assembler for my custom CPU. That way, I can make a program in C and make it run on my CPU. The transsembler was written in Java and is also on the github: https://github.com/milanvidakovic/16-bit-CPU-transsembler

More sensors

This is a followup of my previous post.
I have managed to integrate multiple sensors into a single system capable of sensing if the entrance door is locked/unlocked, if there is a motion inside the apartment and to record the temperature and humidity.
It all started with the status of the entrance door. I wanted a system capable of sensing the status of the lock, but to be able to work without any electrical contacts, since it may corrupt the sensor in time. So I have found an inductive (contactless) switch and I have placed it in the entrance door of my apartment. It is connected to one of my raspberry pi computers, and it sends the information about the state of the door lock to my main server.
The Pi is glued to the wall next to the door:
You may wonder why are the headphones attached to the Pi. They emit the annoying sound of sine waveform, frequency of 3000Hz when the door is unlocked for more than one minute. That way I have a reminder that I need to lock the door.
The red LED is an indicator of the door lock status. If it is red, the door is locked. However, going to the door to see if it is locked or unlocked is not too attractive. I had to invent some way to know the door status without actually going to the door. That is why I have developed the Android application for it:
The lock icon goes red when the door is locked (the time is written below the icon), and goes green when the door is unlocked. The notification comes in real time thanks to the Google Cloud Messaging.
Next came the web portal. I wanted to have the history of door locking and unlocking. That is how I made this web page:

The red cell in the table indicates that there was some motion detected after the door has been locked. This is the proper introduction for the motion detection sensors: after adding door lock and temperature sensors, I wanted to add motion detection sensors inside the apartment. I have used HC SR-501 PIR motion detector:
I have three sensors placed around the apartment and I have a web page which updates the motion information in real time (WebSockets used):

Let us not forget the temperature and humidity sensors: