Learning the Art of Electronics, Week 1

Week 1. Ohms law, power, Kirchhoff`s law V,I.

Ohm`s law V=IR. So what is a Volt ? Potential energy per unit charge or work done to move a charge against electric field, form one potential to a higher potential.

Dynamic resistance Rdynamic= ΔV/ΔI it is the local resistance – the tangent to the slope of the device V-I curve.

Power P=I×V or derived: P=I²R or P=V²/R

Kirchhoff`s law: sum of voltages around circuit is zero, sum of currents in and out of node is zero.

Parallel resistance: Rtotal = (R1×R2)/(R1+R2)

Rule of thumb: if two parallel resistors differ by a factor of ten or more, then we can ignore the larger of two.

In other words: in a parallel circuit, resistor much smaller than other dominates. Ina series circuits, the larger resistor dominates.

Voltage divider. Rely on fact the I is the same on top and bottom.
Vout = Vin × R2 / (R1+R2)
Tip: since the current at the top and bottom are equal, the voltage drops are proportional to the resistances.
So if the lower leg is ten times the upper leg, it will show 90% of the input voltage ( or 10/11 if exactly).
Or if lower leg is 3 times than upper leg, output voltage should be 75% of input voltage ( or 3/4 if exactly ), lets check that:
Thevenin`s model. How to calculate circuit when it gets loaded? Model the actual circuit with the simpler circuit – Thevenin model – which is idealized voltage source with resistor in series.
Then we can rapidly see how that circuit behaves under various loads.
Vthevenin is just open circuit, the voltage when nothing is attached ( no load ).
Rthevenin is Vthevenin/Ishort-circuit 
The fastest way to calculate Rthevenin is to see it as the parallel resistance of several resistances viewed from the output.
Any non ideal voltage source droops when loaded. How much it droop depends on it output impedance. The Thevenin equivalent model, with its Rthevenin describes this property neatly in a single number.
Design rule of thumb: when circuit A drives circuit B. Let Rout for A be <= 1/10 Rin for B.
It means we will pass strong signal to B without big droop.
If RoutA is much smaller then RinB then the divider delivers nearly the all of the original signal.
Labs.
IL.1 nothing to do here, just some information how to use lab stuff.
IL.2 Voltage divider. I have used 10k resistors for voltage divider and 3.9k for load. Results:
So we have voltage divider with 10k resistors. We calculate Rthevenin 5k and Vthevenin 7.5v.
We measure that Vopen is 7.49V that confirms our calculations.
also we measure our Ishort-circuit to be 1.5mA
After measuring we calculate Rthevenin and it is 4.9K and that confirms what we have calculated previously.
Now we load circuit with 3.9V and measure that voltage droop or Vload is 3.2V
And our calculation later confirms our measurements.
Now, if we would like to deliver almost all of the signal to load, by our rule of thumb we should choose Rload to be at least 10 times Rthevenin. Lets choose Rload 56k and see what happens.
And that confirms our rule of thumb: that when loaded with at least 10 times higher resistance we got 90 percent of our signal delivered.
1L.3 I have used analog VOM, in 10v scale I have measured 200k internal resistance.
So it means it moves full scale on 10v with its internal resistance of 200k.
How could one use it to measure for example 50v or 100k ?
We must divide this voltage so that on 50v for example scale would behave same like on 10v, and same for 100v.
We have to add two voltage dividers and calculate resistor values.
We can calculate resistance in two ways: algebraic or just talk our way out.
The bigger the resistance, the more voltage we lose in a dividers leg. In case of 50v we now that we must have 1/5 (10v) on lower leg. Se we must loose 4 from 5 in upper leg. We must choose proportionally bigger resistor in upper leg. 200K times 4 is 800k. That is the value for upper leg resistor in case of 50v.
1L3.3 To get 10mA ammeter from voltmeter we fist calculate current when itsi reading maximum 10v using its internal 200k resistance.
It is I0=10v/200k=50uA
10mA that we need to measure is 200 time bigger that 50uA
So we would add parallel resistor to take 199 parts of current fro 200k and we get 1k resistor. As 1k is way higher that 200k, our internal resistance becomes 1k.

Learning the Art Of Electronics

I have decided to get my self together and systematize my knowledge of electronics. It is very similar situation as for this guy. Electronics is my hobby. And actually one of many hobbies. I would say I have a lot of knowledge it but there are plenty of gaps and places just for intuition. Especially in circuit design.

Once I have purchased a book “Learning The art Of Electronics” and used it as reference for this and that but never when through it.

But this is it.

My goal is to complete one lab at least once a week and post a report here.

Hopefully I will make it through 🙂

 

Materialized view support in different DBMS

Some notes regarding materialized view support in different database management systems.

Materialized view is a database object that stores a snapshot of database query.

If a regular database view could be seen as a “window” – one looks through this window and sees actual situation of the data, then “materialized view ” would be something like a “photo image” i.e., you take an image and can look at it even without going near window, but you only see situation that was on that particular moment picture was taken and if you want to update – you have to take another picture etc.

Different DBMS have different materialized view implementation, lets go thorough most popular ones and look how they are supported.

Oracle

Wikipedia states that oracle was first to implement materialized view in version 8i.

CREATE MATERIALIZED VIEW MV_MY_VIEW
REFRESH FAST START WITH SYSDATE
   NEXT SYSDATE + 1
     AS SELECT * FROM <table_name>;

PostgreSQL

PostgreSQL supports materialized view from version 9.3

CREATE MATERIALIZED VIEW MV_MY_VIEW
 [ WITH ( storage_parameter [= value] [, ... ] ) ]
    [ TABLESPACE tablespace_name ]
     AS SELECT * FROM <table_name>;

SQL Server

SQL server has different concept and it is called Indexed View. The main difference is that such views do not require a refresh because they are in fact always synchronized to the original data of the tables that compound the view. To achieve this, it is necessary that the lines of origin and destination are “deterministic” in their mapping which limits the types of possible queries to do this.

CREATE VIEW MV_MY_VIEW
WITH SCHEMABINDING
AS 
SELECT COL1, SUM(COL2) AS TOTAL
FROM <table_name>
GROUP BY COL1;
GO
CREATE UNIQUE CLUSTERED INDEX XV 
   ON MV_MY_VIEW (COL1);

MariaDB or MySQL

No native materialized view support in MariaDB or MySQL. Can be implemented using FlexiViews.

 

Reliacinė algebra ir norminės formos

Kai kurie žymėjimai ir reliacinė algebra
R={A1,A2,…,An} t.y, R yra lentelės L atributų aibė. Ai kur i=1,…,n yra lentelės atributas. Tada L(R) yra lentelės reliacinė schema.

Lentelės eilučių aibę žymima l={e1,e2,…,em} kur n – lentelės stulpelių skaičius, m – lentelės eilučių skaičius.

Kiekviena eilutė yra sutvarkytas reikšmių rinkinys ej = <a1,a2,…,an> ∈ l;

ai ∈ dom(Ai), kur dom(Ai) yra atributo Ai domenas t.y, galimų reikšmių aibė. i=1,…,n j=1,…,m

Atributų rinkinys apibūdinantis bet kurią lentelės eilutę yra vadinamas viršrakčiu. Viršraktis yra raktas jei pašalinus bent vieną atributą jis praranda universalumą. Taigi raktas yra minimali atributų aibė, vienareikšmiškai apibrėžianti visų atributų reikšmes kiekvienoje eilutėje. Jei raktą sudaro keli atributai, jis vadinamas sudėtiniu raktu.

Lentelėje gali būti keli atributų rinkiniai turintys rakto savybę, visi jei vadinami galimais raktais arba tiesiog raktais. Taigi lentelėje gali būti keli raktai. Vienas iš raktų paskelbiamas pirminiu raktu, dažniausiai trumpiausias.

Lentelės l(R)={e1,e2,…,em} atributų aibės R poaibis V⊆R yra viršraktis, jei  ∀i,j=1,…,m ir i≠j yra teisinga nelygybė ei(V)≠ej(V)

Funkcinė priklausomybė.
Kai atributų aibė A eilutėje vienareikšmiškai apibrėžia atributų aibę B, tai priklausomybė tarp A ir B atributų vadinama funkcinė ir žymima A→B.

A→B reikšia, jog A funkciškai apibrėžia B arba B funkciškai priklauso nuo A. Kairė žymėjimo pusė vadinama Determinantu.

Funkcinė priklausomybė gali būti:

  • trivialioji, kai {B1,B2,…,Bm} yra aibės {A1,A2,…,An} poaibis;
  • netrivialioji, jei egzistuoja bent vienas Bi, Bi∈{B1,…,Bm} ∧ Bi∉{A1,…,An};
  • visiškai netrivialioji, jei ∀i:1,…,m : Bi∉{A1,…,An}.

Pirmoji norminė forma

Lentelė atitinka pirmą norminę formą kai visi lentelės atributai yra nedalomi, t.y., atributuose nesaugomi sąrašai ar kitokios sudėtinės reikšmės.

Pvz., lentelė Dėstytojai={Id, Vardas,Pavardė,Mokymo_įstaigos}, kurios eilutėje saugomos tokios reikšmės {“1”, “Vardis”,”Pavardis”,”VU,KTU,VPU”} netenkina pirmos norminės formos reikalavimo nes lauke Mokymo_įstaigos saugomas reikšmių aibė. Tokią lentelę galima būtų normalizuoti į sekančia tris lenteles:

Dėstytojai={Id,Vardas,Pavardė}

Įstaigos={Id,Pavadinimas}

Dėstytojų_įstaigos={Dėstytojo_Id, Įstaigos_Id}

Visos trys naujos lentelės atitiktų 1NF.

Antroji norminė forma

Lentelė atitinka antrą norminę formą kai ji yra 1NF ir neturi tokių atributų kurie funkciškai priklausytų tik nuo rakto dalies (kai raktas yra sudėtinis).

Pavyzdžiui, turime lentelę Dėstytojų_įstaigos={Dėstytojo_Id, Įstaigos_Id,Įdarbinimo_data,Įstaigos_adresas}

Ši lentelė nėra antros norminės formos nes turime sudėtinį raktą kurį sudaro atributai Dėstytojo_Id ir Įstaigos_Id ir turime atributą Įstaigos_adresas, kuris funkciškai priklauso tik nuo atributo Įstaigos_Id. Kad lentelė atitiktų antros norminės formos reikalavimus perkelkime atributą Įstaigos_adresas į lentelę Įstaigos.

Trečioji norminė forma

Lentelė atitinka trečiąją normalinę formą kai joje nėra atributų, tranzityviai priklausančių nuo rakto.

Tarkime turime lentelę Dėstytojų_įstaigos={Id, Dėstytojo_Id, Įstaigos_Id, Įstaigos_adresas}

Joje raktą iškėlėme į lauką Id ir dabar Įstaigos_adresas nepriklauso nuo rakto dalies todėl lentelė atitinka 2NF, tačiau Įstaigos_adresas tranzityviai priklauso nuo Id t.y., Id->Įstaigos_Id->Įstaigos_adresas, todėl lentelė neatitinka 3NF.

Kad lentelė atitiktų 3NF formos reikalavimus perkelkime atributą Įstaigos_adresas į lentelę Įstaigos.

Boiso-Kodo norminė forma

Lentelė laikoma atitinkanti BKNF jei ji yra 1NF ir kiekvienos netrivialios FP determinantas ( FP kairioji dalis, Determinantas->Kažkas_tai ) yra viršraktis.

Tarkime turime lentelę L(X,Y,Z) kuri yra 1NF, lentelės viršranktis yra {X,Y}, funkckinės priklausomybės: {X,Y}->Z ir Z->Y. Kadangi Z->Y ir Z nėra viršraktis, tai lentelė L nėra BKNF.

Ketvirtoji norminė forma

Ketvirtosios norminės formos apibrėžime naudojama daugiareikšmės priklausomybės sąvoka A->->B. Lentelėje L(A,B,C) yra daugiareikšmė priklausomybė jei atributų B aibė, atitinkanti visas atributų A ir C reikšmes, priklauso nuo A, bet nepriklauso nuo C atributų reikšmių.

Lentelė yra 4NF tada, ir tik data, kai kiekviena netrivialiai daugiareikšmei priklausomybei A->->B, A yra lentelės L viršraktis.

First design for 3d printer

My first design for 3d printing!

You can find it on a thigverse: https://www.thingiverse.com/thing:3560965

So that is why it might be a bit over engineered, bu hey, it is fun so who cares 😉

I had some hex type key for automatic yard gate engine disabling and it that plastic handle that got broken over time. So I figured out that this fix could be a good practice to learn Fusion and make my own handle design.

Some design decisions and conclusions if they have worked out or not:

  • Hex key should be fixed to the handle by tightening nut and bolt. That worked out pretty well.
  • I decided that I will split handle horizontally for two reasons: a) it is super easy to print both parts from flat surface without any supports and b) I can select different infill: 100% for bottom part that holds hex key and has to be strong enough and I can select something like 10% for top part that is basically a decorative part.
  • I will use two pins to join top and bottom part. That did not work very well: pins got broken on assembly ( I forgot to make them 100% infill ) and instead of just drilling them out, I just glued top and bottom parts together.
Hex key T handle
Hex key T handle
Hex key T handle Drawing
Hex key T handle Drawing

8086 disassembler using 64 bit assembly language

8086 disassembly application. Project done during computer architecture course.

Project is done using nasm(yasm) 64 bit assembly and some c functions to handle input/output.

I have chosen such technologies because I was curious about few topics:

  • Learning about asm 64 bit programming
  • Compiling assembly executable for windows 64 platform. During the comp architecture course we were doing assembly programming for a ms dos using dosbox. I was interested in making some executable code on a windows 64 platform.
  • Linking assembly code to some higher lever programming language library. During the comp architecture course we were using dos api (int) to handle input, output and some other manipulations. For modern platform you could use windows api function calls or libraries from higher level programming languages. I have chosen to use c and use some basic c input output functions.
  • Understanding assembly procedure calls on 64 platform and differences between win 64 calls and unix/posix 64 calls.
  • Disassembling some simple c applications and exploriing how assembly code is constructed using c compile. To understand how some c function calls are made I have used some super simple c programs that I decompiled using gdb.

This project can be found in github.