2014年10月1日 星期三

Battery Voltage Detector

Need to monitor the battery voltage on PIC32 !?

Here is a web link regarding using LED forward voltage with ADC : link

The battery voltage measured 1.76V as the RED LED forward voltage.
Left:calculated the VDD=3.1V                              Middle:Circuit Diagram                             Right: Calculation

The ADC of LED forward voltage 1.76V got 581 counts.   581 = (1.76/ 3.1)*1024 

The Vdd estimation: Vdd = (1024*1.76 )/ ADC-count   


Trying to figure out BigEndian/LittleEndian

Trying to figure out PIC32 memory order for the BLE packets order sending...


2014年8月7日 星期四

A smaller printf reference!

Found a smaller printf, the website is at HERE

Did a comparison with and without the standard printf on PIC32 MPLABX...

With the standard printf, code size 10968

Without the standard printf, code size 3908



2014年7月15日 星期二

Finding Peak and Valley with 1st Derivative



    
Looks like need some threshold to eliminate small noise bug as the right photo...

 
       ...
      //Randomize the sample as input
      int v = (int)random(-40, 40);
      a+=0.2; A = (int) (80 + sin(a) * (v+50)); //add sine wave
   
      stroke(100, 100, 100);
      line(lastXPos, lastA,   xPos, A); //draw gray samples------------------------------------

      //smooth it
      B = smooth(A, 0.9, B);    
   
      //get 1st derivative
      C = B - lastB;                   //  f''(x) =  f(x) - f(x-1);
      C = (C + lastC) >> 1;        // some easy smooth
         
      stroke(250, 100, 100);
      line(lastXPos, 100+lastB,   xPos, 100+B);          //draw smoothed samples-------------
      line(lastXPos+1, 100+lastB,   xPos+1, 100+B);

      stroke(100, 100, 250);
      line(lastXPos, 400+(lastC*8),   xPos, 400+(C*8));//draw 1st derivatives  --------------
      if ((C*lastC) <= 0) {
        //f'(x) changed; when (f'(x)>0, f'(x-1)<0) or (f'(x)<0, f'(x-1)>0) or f'(x)=0 or f'x(x-1)=0    
        if (lastC >0)  {//found valley, draw line------
           stroke(40,40, 60);
           line(xPos, 400, xPos, 200);
           }
        if (lastC <0)  {//found peak, draw line-------
           stroke(80,80, 120);
           line(xPos, 400, xPos, 150);
           }
        }
 
      lastA = A;           //store current value for next iteration
      lastB = B;
      lastC = C;
   
      lastXPos = xPos; //move forward
      ...
Change random samples into Perlin noise

2014年7月4日 星期五

SI1143 Heartbeat Pulse Evaluate

Arduino reading
SI1143 setup
Processing Arduino SI1143 red data (baud:57600, samples:10)
After the SI1143 carefully setup, the total red light (IR+visible) data send to Processing for drawing, looks like finger tip is the best monitor place...
Processing red data w/ HRV (baud:115200, samples:2)

















































Processing red data w/ HRV (baud:115200, samples:1)
Improved one read from 2.5ms to 0.9ms, w/ some beers... (samples:4)










2014年7月3日 星期四

SI1143 Evaluate:Ambient Light, Proximity, Temperature


As default setup,
LED current sunk: 0x01, ~10cm stable detection
LED current sunk: 0x0F, ~30cm+ stable detection



...
  write_reg(HW_KEY, 0x17); 
  //0x0F:30cm detection, 0x01:10cm dectection
  write_reg(PS_LED21,0xFF); 
  write_reg(PS_LED3, 0x0F); 
  //Enable AUX as well
  param_set(CHLIST,0b01010111);
...