Q&A from embedded programming [P1]
- 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)
- 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)
- 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
- I have a pointer and want to assigned it to an absolute address: 0xabcd with a value 12345 how can I implement it?
- int *ptr;//declare pointer
- ptr =(int*)0xabcd;// cast the address to pointer
- *ptr = 12345;//assign value to pointer
- Interrupt: from https://rmbconsulting.us/publications/a-c-test-the-0x10-best-questions-for-would-be-embedded-programmers/
- interrupt can't return value
- ISR can't be passed by parameter but the interrupt service vector
- ISR should be short, floating point should be avoided.
- 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
- Given var = 0xD6
- Question: what is value of ~var in 8 bit?
- Because AVR using little-endian therefore the MSB will be on the right side
~(0x00D6) = 0x 00 00 04 09
- Difference between EEPROM and Flash?
- EEPROM can be erased by single byte because it is stored by electron tunneling
- EEPROM - erase single byte/ FLASH - erase block
- What is the difference between Dev Board and Eval Board?
- 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
- Development board is different, it is full armor board that you can use to write code right away without thinking about buying external peripheral.
- Why don't we use voltage divider instead of PWM
- http://forum.arduino.cc/index.php?topic=211137.msg1549343#msg1549343
- All of the power will be consumed by the resistor