2017年7月16日 星期日

Competitive Programmer’s Handbook Note.

1.g++ compiler provide __int128_t type 128 bits interger

2.Because the precision errors it's better use subtraction and compare with a small number like(1e-9) than use == to indicate two floating point numbers is equal.

3.page 16 book list

4.Computers and Intractability: A Guide to the Theory of NP-Completeness

5.Kadane’s algorithm.

6.Chapter 7 DP

2017年6月11日 星期日

NANO100:Using data flash without the external 12M HZ crystal.

The data flash start address is set by register so it need a reset after update the address, but in default it will use  the external 12M HZ crystal.It's need to modify the CFOSC .



Modify the \SampleCode\StdDriver\FMC_RW set_data_flash_base() function



Ref:
     Nano100 Series Technical Reference Manual

NANO100:Enable printf use Nu-Link to send massage

1.Add #define DEBUG_ENABLE_SEMIHOST in Library\StdDriver\src\retarget.c .
 

2.Start Keil C IDE debug session and enable the View\Serial Windows\UART #1.


3. Now you can see the printf massage in Keil C IDE.

Ref:
   2. Semihosting

2017年6月7日 星期三

Octave: Modulation Sine Wave use PWM generate look up table for MCU DAC.

Input the target sample frequency ,sample bits and sample frequency.Generate the duty of PWM(percentage).
Code:
Avoid the negative part cause normally MCU didn't have negative voltage output ability.







Ref:
    1.http://bugworkshop.blogspot.tw/2011/04/blog-post_12.html

2017年5月26日 星期五

NANO100: MCU Sine wave generator - using MCU DAC(Look up table with adjustable amplitude)

1.Generate sample point use octave.

2.Create look up table.use const to store look up table in ROM for less latency.

3.Scale to real data function (for 12 bits DAC the max value is 4096)

2017年5月11日 星期四

nrf52 : Add CMSIS_DSP package in Keil 5

1.Open Manage Run-Time Environment and check the DSP














2.Include arm_math.h
  and  path in your project:Keil_v5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\Include

3.Add symbol ARM_MATH_CM4 since nrf52832 use Cortex M4F






4.Simple matrix multiplication code

Ref:
    1. CMSIS DSP Software Library







2017年4月19日 星期三

Use ADC to measure battery.

In my project I use a 8 bits resolution ADC to measure battery . 3.0 V as 100% and 2.2 V as 0%.
When input is 3.0 V the ADC value is 255 and 2.2 V for 180. Because it's unnecessary to be very accurate so I use simple equation y = ax +b to calculate the percentage of the battery.

100 = 255 a + b ........ (1)
0     = 180 a + b ........ (2)

Use 1 and 2 we can calculate a = 4/3 and b = -240.











Ref:
      Float divide and integer divide in C.

Linux driver: How to enable dynamic debug at booting time for built-in driver.

 Dynamic debug is useful for debug driver, and can be enable by: 1. Mount debug fs #>mount -t debugfs none /sys/kernel/debug 2. Enable dy...