Showing posts with label EE. Show all posts
Showing posts with label EE. Show all posts

Thursday, December 12, 2019

How VU meter works?

I meet a cool classmate name Tri who major in CS and wants to program a microcontroller. I'm just a noob in a microcontroller world but I love to explore new things.
We come up with an idea, making a VU with Christmas light.

After looking at other projects, I realize that a microcontroller will read AC signal from an output source, then it will separate the voltage into each level and display them accordingly.

Let's look at a snippet from Instructable(1):
else
    {
      for (i = 0; i < input; i++)
      {
        digitalWrite(led[i], HIGH);
        delay(4);
      }
      for (i = i; i < 11; i++)
      {
        digitalWrite(led[i], LOW);
      }
    } 

In the above code, maxInput is 12. Whenever there is a signal, LEDs that are less than the threshold will turn ON. Then, they will be set back to OFF.

Another example from Instructable(2):

GreatScott uses an analog approach.
  1. Audio (AC) is the main input source (1.3V).
  2. Create threshold values for 7 rows.
  3. So we use LM324 opamp to amplify the signal from 1.3V to 8V.
  4. Then, we build 7 comparators using the same type of opamp.
  5. Then we use MOSFET as a switch
  6. Control by using V_GS

Thursday, August 8, 2019

Generate Signal with Aduino

So I have a school project that requires sending square waves to a piezo controller. We avoid using Arduino Toolbox in Matlab because we have other peripherals that being controlled.
Our solution is to use serial communication in Matlab to control the Arduino board. Here is our code

Arduino:

unsigned long halfPeriod = 5000UL; // 5mS = 1/2 100 Hz
// don't use a floating # for delay, delayMicroseconds

void funcGen(){
  digitalWrite(11, LOW);
  delay(30);
  for(int i = 0; i< 8; i++){
      PINB = PINB | 0b00101000; // x-x-13-12-11-10-9-8 on Uno,
                            // toggle output by writing 1 to input register
      delayMicroseconds(halfPeriod);
    }
}

void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite (13, HIGH); // known starting level
pinMode(11, OUTPUT);
digitalWrite (11, LOW); // known starting level
}

void loop(){
if (Serial.read() > 0){
  funcGen();
  Serial.flush();
  }
}

Matlab:

arduino=serial('COM3','BaudRate',9600);
fopen(arduino)
fprintf(arduino,'1');
fclose(arduino);

Sunday, May 19, 2019

Calculate the length of monopole antenna

We have the formula for wavelength

in which c is the speed of light = 3*10^8 m/s

Practical Example:
A student has a receiver (MX-RM-5V) and a transmitter (FS1000A) in the 433MHz band. When he/she run the basic code sending "hello world", the distance between them is less than 10 cm. In order to increase the transmission distance, what is the length of the antenna should he/she add?

3*10^8 / 433 * 10^6  =  0.6928 meter

so for half-wavelength antenna: 0.5 * 0.6928 = 0.3464 meter
and for quater-wavelength antenna: 0.25 * 0.6928 = 0.1732 meter or 17.32 cm

That is the reason we want to add the carrier frequency to reduce the length of the antenna.

The range is improved significantly after the antennas are inserted



Thursday, April 26, 2018

S-Parameter or Reflection Coefficient

S_11 = 0 dB: all power is reflected back to antenna
S_11 = -10 dB
S_11 = reflected signal / transmitted signal
S parameter is also called reflection coefficient 



Saturday, April 21, 2018

Antenna Index


VSWR

>> Voltage Standing wave ratio is defined as:
>> \Gamma is the voltage reflection coefficient at the input terminal of the antennas 
Z_in = antenna input impedance 
Z_o = Characteristic impedance of the transmission (Tx) line

>> So what is the Tx line or transmission line?
The transmission line is two wires running parallel to each other
To find the Z_o (characteristic impedance) we can measure the voltage across and current of those two lines. Then, apply Ohm's law to find the impedance 

Furthermore, the Tx line is also represented as:
In which: 
L: magnetic field around the wire
R: resistance across 2 wires
C: how electron repel each other
G: dielectric material separate conductors

Tuesday, December 19, 2017

Q&A from embedded programming [P1]


  1. What is volatile and when, and why we should use it?
    • volatile is a variable that compiler will not optimize and it can change unexpectedly.  
    • It's used for hardware interaction such as operation in OS/RTOS, hardware register access, interrupts, or multi-core processor. (source: stackoverflow, prof. Ken Arnold at SDSU)
  2. Timing specs:
    • Tphl: propagation delay from high to low
    • Tplh: propagation delay from low to high
    • Tsu: set up time, minimum time before the clock arrive
    • Th: hold time, minimum time after the clock arrive 
    • Tpckq: propagation delay from clock to Q (in flip flop)
  3. What is the UL in preprocessor for example #define FPT 16000000UL
    • UL is unsigned long, we use that expression because 16 000 000 is greater than 2^(bit of microprocessor, 16, 65536). 
      • similar to #define F_CPU ((unsigned long)1200000)
    • so how many bit can UL store? 2^16
  4. I have a pointer and want to assigned it to an absolute address: 0xabcd with a value 12345 how can I implement it?
    1. int *ptr;//declare pointer
    2. ptr =(int*)0xabcd;// cast the address to pointer 
    3. *ptr = 12345;//assign value to pointer
  5. Interrupt: from https://rmbconsulting.us/publications/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers/
    1. interrupt can't return value
    2. ISR can't be passed by parameter but the interrupt service vector 
    3. ISR should be short, floating point should be avoided.
  6. How can we represent signed number in 8bit - AVR?
    • For example, what is the value of variable of x in hexadecimal?
    • signed int x=-1, -5, 1, 0, 127, 128,
    • Note: remember in AVR we use two's complement for signed number 2^8 = 256 will range from  -128 to 127, and unsigned will range from 0 - 255
      0 --binary--> 0000 0000 --2s_complement--> 0000 0000
      1 --binary--> 0000 0001 --2s_complement--> 1111 1110 + 1 = 1111 1111
      -1 --2s_complement--> 0000 0001 - 1 = 0000 0000 --binary--> 1111 1111
      -5 --2s_complement--> 0000 0101 -1 = 0000 0100 --binary--> 1111 1011
      5 --binary--> 0000 0101 --2s_complement--> 1111 1011
  7. Given var = 0xD6
    1. Question: what is value of ~var in 8 bit? 
      1. Because AVR using little-endian therefore the MSB will be on the right side
        ~(0x00D6) = 0x 00 00 04 09
  8. Difference between EEPROM and Flash?
    1. EEPROM can be erased by single byte because it is stored by electron tunneling
    2. EEPROM - erase single byte/ FLASH - erase block
  9. What is the difference between Dev Board and Eval Board?
    1. Evaluation board is the basic board that you have to connect other peripherals in order to work because it has only basic components such as leds, button
    2. Development board is different, it is full armor board that you can use to write code right away without thinking about buying external peripheral.
  10. Why don't we use voltage divider instead of PWM
    1. http://forum.arduino.cc/index.php?topic=211137.msg1549343#msg1549343
    2. All of the power will be consumed by the resistor

Tuesday, February 14, 2017

EE-340: Chap 1 - Vector Calculus

Question and Answer:


  1. Why midpoint is equal (x+y)/2 not (x-y)/2
    I will answer by a graph

Friday, February 10, 2017

Chapter 8: Building Blocks of integrated-circuit amplifier

REF:
http://aries.ucsd.edu/NAJMABADI/CLASS/ECE102/12-F/NOTES/

http://cc.ee.ntu.edu.tw/~lhlu/eecourses/Electronics2/Electronics_Ch6.pdf

Vocab:
cascading: arrange in a series: xep tang
Intrinsic gain: Avo when Rc reach infinity _ Avo= -gm*ro
Overdrive Voltage: Vov is the voltage passing threshold voltage Vt

Review MOS and BJT:
For BJT, Vbe = 0.7 is a key to find other node voltages and branch currents
For MOS, Id is a key to find the others.

Question and Answer:

  1. When is Vov = Vgs?
  2. Why voltage source for MOS is Vdd and Vcc for BJT?


Thursday, January 19, 2017

Diode

I’m not an organized person but lately I realized that keeping documentation is really important. Especially, when we learn more and we get older. So I decide to write down everything I’ve learned in this blog.
I also try to apply Feynman technique to simplify the concept and engrave more information.

Books: Electronics All-in-One For Dummies by Doug Lowe