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