Basys2 and four bit binary to decimal number into seven segment led display

2016-03-21 20.22.56At first the good idea is to draw down signals from the  input to the output. Basically it is the truth table:

In the header we can see seven segment display led signals (ca…cg)

Out – decimal number I hope to display and sw3…sw0 input in binary.

-------------------------------------------------
--ca |cb |cc |cd |ce |cf |cg |out|sw3|sw2|sw1|sw0
-------------------------------------------------
-- 1 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 1
-- 0 | 0 | 1 | 0 | 0 | 1 | 0 | 2 | 0 | 0 | 1 | 0
-- 0 | 0 | 0 | 0 | 1 | 1 | 0 | 3 | 0 | 0 | 1 | 1
-- 1 | 0 | 0 | 1 | 1 | 0 | 0 | 4 | 0 | 1 | 0 | 0
-- 0 | 1 | 0 | 0 | 1 | 0 | 0 | 5 | 0 | 1 | 0 | 1
-- 1 | 1 | 0 | 0 | 0 | 0 | 0 | 6 | 0 | 1 | 1 | 0
-- 0 | 0 | 0 | 1 | 1 | 1 | 1 | 7 | 0 | 1 | 1 | 1
-- 0 | 0 | 0 | 0 | 0 | 0 | 0 | 8 | 1 | 0 | 0 | 0
-- 0 | 0 | 0 | 1 | 1 | 0 | 0 | 9 | 1 | 0 | 0 | 1
-- 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0

Now we have functional relation between the input and the output so lets implement it in VHDL:

process (sw)
BEGIN
case sw is
	when "0001" => segment7 <= "1001111"; -- 1
	when "0010" => segment7 <= "0010010"; -- 2
	when "0011" => segment7 <= "0000110"; -- 3
	when "0100" => segment7 <= "1001100"; -- 4
	when "0101" => segment7 <= "0100100"; -- 5
	when "0110" => segment7 <= "1100000"; -- 6
	when "0111" => segment7 <= "0001111"; -- 7
	when "1000" => segment7 <= "0000000"; -- 8
	when "1001" => segment7 <= "0001100"; -- 9
	when "0000" => segment7 <= "0000001"; -- 0
	when others => segment7 <= "1111111"; -- blank
end case;
END process;

Quite easy :) - full code is locating https://github.com/margusja/binary2decimalLed/blob/master/one.vhd

But this is not I want. In hardware we can not do thinks like case. So lets move closer to the hardware.

Screen Shot 2016-04-06 at 22.36.30
This is not optimized solution but much closer to hardware than previous one. 

Update
Got time and optimized logic.
13087789_1608990496089069_6114430185435126336_n 

And sentences are much better compared previous ones:
--ca <= (not sw3 AND not sw2 AND not sw1 AND sw0) OR (not sw3 AND sw2 AND not sw1 AND not sw0);
ca <= (not sw0 AND sw2 AND not sw3) OR (sw0 AND not sw1 AND  not sw2 AND not sw3);
cb <= (sw0 AND not sw1 AND sw2 AND not sw3) OR (not sw0 AND sw1 AND sw2 AND not sw3);
cc <= (not sw3 AND not sw2 AND sw1 AND not sw0);
--cd <= (not sw3 AND not sw2 AND not sw1 AND sw0) OR (not sw3 AND sw2 AND not sw1 AND not sw0) 
--		OR (not sw3 AND sw2 AND sw1 AND sw0) OR (sw3 AND not sw2 AND not sw1 AND sw0);
cd <= (sw0 AND not sw1 AND not sw2) OR (not sw0 AND not sw1 AND sw2 AND not sw3) OR 
		(sw0 AND sw1 AND sw2 AND not sw3);
--ce <= (not sw3 AND not sw2 AND not sw1 AND sw0) OR (not sw3 AND not sw2 AND sw1 AND sw0) 
--			OR (not sw3 AND sw2 AND not sw1 AND not sw0) OR (not sw3 AND sw2 AND not sw1 AND sw0)
--			OR (not sw3 AND sw2 AND sw1 AND sw0) OR (sw3 AND not sw2 AND not sw1 AND sw0);
ce <= (sw0 AND not sw3) OR (not sw1 AND sw2 AND not sw3) OR (sw0 AND not sw1 AND not sw2);
--cf <= (not sw3 AND not sw2 AND not sw1 AND sw0) OR (not sw3 AND not sw2 AND sw1 AND not sw0)
--		OR (not sw3 AND not sw2 AND sw1 AND sw0) OR (not sw3 AND sw2 AND sw1 AND sw0);
cf <= (sw1 AND not sw2 AND not sw3) OR (sw0 AND not sw2 AND not sw3) OR (sw0 AND sw1 AND not sw3);
--cg <= (not sw3 AND not sw2 AND not sw1 AND sw0) OR (not sw3 AND sw2 AND sw1 AND sw0)
--		OR (not sw3 AND not sw2 AND not sw1 AND not sw0);		
cg <= (not sw1 AND not sw2 AND not sw3) OR (sw0 AND sw1 AND sw2 AND not sw3);

Full adder in Basys2 in VHDL

Plan – and truth table

2016-03-21 22.14.43

Code in github – https://github.com/margusja/FullAdder

And some pics

a is on, result sum is on

2016-03-21 20.22.19
b is on, result sum is on
2016-03-21 20.22.56
a, b, overflow are on, result sum on and output overflow is on
2016-03-21 22.14.30

(Arduino -> Atmega328P) + RTC + MCP23008 + LCD = kell

Tuli tahtmine kella ehitada.

Vanast ajast oli olemas LCD 16X4, RTC ja arduino R3

Ullult olin soetanud LCD expanderi – https://taaralabs.eu/lcd-plug/

RTC annab kella võimaluse. Kui toide välja võtta, siis kenasti tiksub edasi ja hoiab kellaaega õigena.

MCP23008 – annab vabaks hulga arduinio porte, vastasel juhul poleks ilmselt RTC ka kuhugi panna.

Hetkel selline laiali prototüüp, kes teab kas see kuhugi kaugemale jõuabki.

2016-01-26 22.09.30

Koodiosa tuleb kõvasti tuunida, hetkel suht häbi selle osa üle.

Näiteks on nädalapäev ühe päeva võrra nihkes.

Esimene versioon tõesti halba koodi – https://github.com/margusja/ArduinoRTC

 

Osa2

Kuna kogu arduino plaati ühe kella alla matta on minu jaoks liigne luksus, siis otsustasin selle osa eraldi Atmega328P kätte anda. Alguses oli plaan ilma välise kellata, aga hetkel on siis välise 16MH kellaga.

Ühendasin ISP atmega328P’ga:

icsp_hookup

Allikas: http://upvector.com/atmega/

 

Minul sai selline asi. Programmaator on mul avrispmkII

2016-01-28 21.55.22

Ja oh seda õnne:

margusja@IRack:~/Documents/Arduino/hardware/breadboard/avr$ avrdude -c avrispmkII -v -p ATMEGA328P -P usb

avrdude: Version 5.11.1, compiled on Feb 12 2013 at 01:24:54
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2009 Joerg Wunsch

System wide configuration file is “/usr/local/CrossPack-AVR-20130212/etc/avrdude.conf”
User configuration file is “/Users/margusja/.avrduderc”
User configuration file does not exist or is not a regular file, skipping

Using Port : usb
Using Programmer : avrispmkII
avrdude: usbdev_open(): Found AVRISP mkII, serno: 000200133546
AVR Part : ATMEGA328P
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PC2
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :

Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
———– —- —– —– —- —— —— —- —— —– —– ———
eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff
flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff
lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00

Programmer Type : STK500V2
Description : Atmel AVR ISP mkII
Programmer Model: AVRISP mkII
Hardware Version: 1
Firmware Version Master : 1.23
Vtarget : 5.1 V
SCK period : 8.00 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DE
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

avrdude done. Thank you.

Part 3

Peale juhtmete ümbertõstmist ja uue kivi programmeerimist on pilt ikka segane, aga arduino sai vahelt minema.

2016-01-29 20.00.32

 

Kuna on plaanis kivil lock bitte ja fuses muuta, siis tundub, et siinkohal on ka õige praegused setingud maha kirjutada

avrdude -c avrispmkII -v -p ATMEGA328P -P usb -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h

Reading | ################################################## | 100% 0.00s

avrdude: writing output file “<stdout>”
0xff
avrdude: reading hfuse memory:

Reading | ################################################## | 100% 0.00s

avrdude: writing output file “<stdout>”
0xda
avrdude: reading efuse memory:

Reading | ################################################## | 100% 0.00s

avrdude: writing output file “<stdout>”
0x5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as DA
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

Ja ega ma neid peast ei arvuta – http://www.engbedded.com/fusecalc/

 

Part 4.5 – Asja lihtsustamiseks võtsin kasutusele sisemise kella (avrdude: safemode: lfuse reads as C2).

Nüüd on prototüüp võimalikult lihtne.

Making The Internet

Vol1 – Sisu ehitamine

Internet peab paistma elus, seega peab internet vähemalt vilkuma.

Minu eesmärk oli kasutada nn vanakooli lahendust, kus vilkumisel kasutatakse kondensaatori omadust, mitte programmeerida vilkumist. Kasutasin skeemi, mis on toodud joonisel 1.

 

simple3

Joonis 1. Allikkas: http://cappels.org/dproj/simplest_LED_flasher/Simplest_LED_Flasher_Circuit.html

Ma 2N2222 ei leidnud, aga mul oli kodus 2N2219A, mis toimib samuti.

Kiire prototüüp toimib.

2015-12-30 12.08.34

Pildil olev parempoolne kivi ei ole ühendatud.

Varsti tuleb vol2 – internet peab olema ka ilus.

Fuzzy

We start by defining the input temperature states using “membership functions”:
Fuzzy

 

With this scheme, the input variable’s state no longer jumps abruptly from one state to the next. Instead, as the temperature changes, it loses value in one membership function while gaining value in the next. In other words, its ranking in the category of cold decreases as it becomes more highly ranked in the warmer category.

At any sampled timeframe, the “truth value” of the brake temperature will almost always be in some degree part of two membership functions: i.e.: ‘0.6 nominal and 0.4 warm’, or ‘0.7 nominal and 0.3 cool’, and so on.

 

In practice, the controller accepts the inputs and maps them into their membership functions and truth values. These mappings are then fed into the rules. If the rule specifies an AND relationship between the mappings of the two input variables, as the examples above do, the minimum of the two is used as the combined truth value; if an OR is specified, the maximum is used. The appropriate output state is selected and assigned a membership value at the truth level of the premise. The truth values are then defuzzified. For an example, assume the temperature is in the “cool” state, and the pressure is in the “low” and “ok” states. The pressure values ensure that only rules 2 and 3 fire:

 

Fuzzy_control_-_Rule_2_evaluation Fuzzy_control_-_Rule_3_evaluation

 

https://en.wikipedia.org/wiki/Fuzzy_control_system

Arduino and GPRS shield

Made first prototype used GPRS shield SIM900

http://positrontech.in/uppdf/GSM/SIM900%20%20Module.pdf

500px-GPRS_shield_v1.4

http://garden.seeedstudio.com/images/a/a0/SIM900_ATC_V1_00.pdf

First I had to disable SIM pin1

Screenshot 2015-06-25 20.13.10

 

List of operators

Screenshot 2015-06-25 23.08.48

 

So I made one call and send one SMS to Varulla.

2015-06-24 20.37.57

 

2015-06-26 21.12.10

 

Now we have dial pad prototype.

2015-06-28 20.19.51

IoT – Raspberry Pi2 and hc-sr04

Lately I discovered IoT and Clayster for my self.

One good way to learn new things is to resolve some problem using new technology. So I thought to build system detects is somebody is behind in my display. And I’d like to detect it over XMPP.

So for prototyping Raspberry Pi is suitable piece of hardware. Also I used ultrasonic sensors – hc-sr04

2015-05-27 15.34.52

 

Connected with RP using schema

hc-sr04-tut-2

Source: http://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi

 

And I can read readings over XMPP

 

 

 

 

 

Screenshot 2015-05-27 15.30.55

 

And finally the most coolest thing – HomeArena by Clayster

Screenshot 2015-05-28 13.15.54