Posts

An Easy Way To Remember Logic Gates Outputs

 When we think of multiple inputs logic gates, it is better to use a simple rule to find output of a logic gate. We will talk about six logic gates AND, NAND, OR, NOR, XOR, XNOR , one by one. AND Gate: As we know, output of an AND gate is 1 if all inputs are 1. So, we can say that if any bit in the input is 0 then the output will be 0. NAND Gate: As we know, NAND is NOT AND i.e. complement of an AND gate. So, if any bit in the input is 0 then the output will be 1. OR Gate: As we know, output of an OR gate is 1 if any input is 1. NOR Gate: As we know, NOR is NOT OR i.e. complement of an OR gate. So, if all inputs are 0 then the output will be 1. XOR Gate: If odd number of inputs are 1 then the output will be 1. XNOR Gate: If even number of inputs are 1 then the output will be 1. Happy reading and Thank you. Meet you soon.

Programming An FPGA Is Joy

 When we learn an HDL to program an FPGA by following examples from books and online. We always see ports like 3 downto 0, 7 downto 0. In this way we use same switches or leds again and again which might make a few switches unusable in the near future and remaining switches will be intact. So, in place of 3 downto 0 we can use 5 downto 2,15 downto 12 and so on. Another point is that we can name ports as sw1, sw2 and so on. But there is difficulty in port map to assign each switch individually. So, we should use array like naming sw[0], sw[1] and so on which helps in port map. I think that using a wrapper file for mapping ports in a constraint file is far better than directly editing a constraint file.  

Geometric Progression

  Geometric progression has a common ratio between two adjacent terms.  Here we are going to write a file named gp.tcl and then we will run it as, tclsh gp.tcl  #gp.tcl # Geometric progression # a = initial term # n = nth term # r = common ratio proc nthGP {a r n} { set an [expr {$a * pow($r, ($n - 1))}]; return $an; } proc sumGP {a r n} { set sum 0; if {$r > 1} { set sum [expr {($a * ( pow($r, $n) - 1)) / ($r - 1)}]; } elseif {$r < 1} { set sum [expr {($a * (1 - pow($r,$n))) / (1 - $r)}]; } return $sum; } #Examples puts "5th term of a GP with  r = 1.5 and a = 2: [nthGP 2 1.5 5]"; puts "Sum of 5 terms of a GP with  r = 1.5 and a = 2: [sumGP 2 1.5 5]"; puts "5th term of a GP with  r = 0.5 and a = 2: [nthGP 2 0.5 5]"; puts "Sum of 5 terms of a GP with  r = 0.5 and a = 2: [sumGP 2 0.5 5]"; Happy reading and thank you. Meet you soon.

Finding The Number Of Digits In A Number Part 2

  Finding the number of digits in a number using math functions. Here we are going to write a file named digitcountp2.tcl and then we will run it as,  tclsh digitcountp2.tcl #digitcountp2.tcl # The number of digits in a number. proc dcnt {num} { set number $num; set digicnt 0; if {$number != 0} { if {$number < 0} { set number [expr {$number * -1}]; } set digicnt [expr {floor(log10($number) + 1)}]; } return $digicnt; } #Examples puts "Number of digits in 00: [dcnt 00]"; puts "Number of digits in 2019: [dcnt 2019]"; puts "Number of digits in -123: [dcnt -123]"; Happy reading and thank you. Meet you soon.

Finding The Number Of Digits In A Number Part 1

 Do you need to find the number of digits in a number ?  Here we are going to write a file named digitcountp1.tcl and then we will run it as,  tclsh digitcountp1.tcl  #digitcountp1.tcl # This procedure counts the number of digits # in a number. proc dcnt {num} { set number $num; set digicnt 0; if {$number != 0} { if {$number < 0} { set number [expr {$number * -1}]; } while {$number != 0} { incr digicnt; set number [expr {$number / 10}]; } } return $digicnt; } Happy reading and thank you. Meet you soon.

The Maximum Of Numbers

 The maximum of a list of numbers is the largest number among that numbers.  Here we are going to write a file named max.tcl and then we will run it as, tclsh max.tcl  #max.tcl # proc max {args} { set max [lindex $args 0]; foreach num $args { if {$num > $max} { set max $num; } } return $max; } #Examples # puts "The maximum out of 5, 18 and 200: [max 5 18 200]"; puts "The maximum out of 201, 5, 18 and 200: [max 201 5 18 200]"; puts "The maximum out of 5, 18, 200 and 300: [max 5 18 200 300]"; Happy reading and thank you. Meet you soon.

Fibonacci Numbers

 In Fibonacci Numbers , the next number is the sum of previous two numbers.   Here we are going to write a file named fib.tcl and then we will run it as, tclsh fib.tcl  #fib.tcl # proc nthFib {n} { #Base conditions if {$n == 1} { return 0; } elseif {$n == 2} { return 1; } elseif {$n > 2} { set a 0; set b 1; set sum 0; for {set i 2} {$i != $n} {incr i} { set sum [expr {$a + $b}]; set a $b; set b $sum; } return $b; } } #Examples puts "1st number in the fibonacci numbers: [nthFib 1]"; puts "2nd number in the fibonacci numbers: [nthFib 2]"; puts "5th number in the fibonacci numbers: [nthFib 5]"; puts "8th number in the fibonacci numbers: [nthFib 8]"; puts "11th number in the fibonacci numbers: [nthFib 11]"; Happy reading and thank you. Meet you soon.