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.

nrf52: Change pin 0.09 and pin 0.10 as normal GPIO

1.Open project option -> C/C++ and add CONFIG_NFCT_PINS_AS_GPIOS to preprocessor symbols.


2,Now you can use pin 0.09 and pin 0.10 as normal GPIO



Ref:

2017年4月15日 星期六

nrf52: Use PWM to control DC motor rotate speed.

DC motor rotate speed is directly proportional  to supply voltage and current. But it is very difficult to use software to control supply voltage and current . So use on/off time to control the DC motor is a better solution.

In my project I use TI DRV8837  to driver. DRV8837  has H-bridge structure to control motor forward/reverse rotate. So just simply add pwm input to DRV8837 then we can control the DC motor rotate speed.

1.Connect three gpio to DRV8837 nSleep , IN1 , IN2 .


2.Config PWM module and connect to IN1,IN2.   

3.Now we can control DC motor rotate speed from 0 to 100% and rotate forward/reverse.



NOTICE!: It very danger when motor change rotate direction because it will shortly to turn both side H-bridge ON.It will need a short dead zone to prevent this situation.Luckily DRV8837 has build- in protection function when both IN1 IN2 are high the output will be low to stop the motor.

Ref:
     1. DRV883x datasheet 
     2. H-bridge
        

2017年4月12日 星期三

nrf52:Use DC/DC regulator to save power consumption

nrf52832 has two power mode.LDO mode and Switching power mode.To use Switching power mode will need to add Inductor  between the DEC4 pin and DCC pin, and use software to change mode.




in softdevice :




It can save 5~6 uA around 17% of current on ble_template project








Ref:
       1. LDO vs Switching power
       2. nRF52 Online Power Profiler
       

nrf52: merge softdevice and application hex.

Add nrfTool mergehex to enviroment path .

Type mergehex -m softdevice.hex application.hex -o your.hex

2017年4月5日 星期三

Use Astyle in Keil uVision

1.Download Astyle
   http://astyle.sourceforge.net/
2. Open Keil -> Tool -> Customize Tool Menu config as below

My argument. Can customize as you want.
a.Astyle Current File :
--style=allman --indent-switches -n --indent=tab --indent-labels --indent-preprocessor -p -U !E
b. Astyle All File        :
 --style=allman --indent-switches -n --indent=tab --indent-labels --indent-preprocessor -p -U "$E*.c" "$E*.h"


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...