Search This Blog

Thursday, November 26, 2015

DAC - Digital to Analog Converter

PWM (Pulse Width Modulation) တွေကို analog output တွေအနေနဲ့ အသုံးများပေမယ့် သူတို့က high frequency, high accuracy, hard real-time တွေအတွက်တော့ မသင့်တော်ဘူးလို့ ထင်ပါတယ်။ Analog signal အစစ်မထွက်တဲ့ အတွက် RC low pass filter ခံ သုံးပြန်ရင်လည်း ရလာမယ့် phase lag က hard real-time system တွေမှာ ပြဿနာ အကြီးကြီးပါ။ စျေးပေါ၊ သေးငယ်တဲ့ AD5641 လို DAC လေးတွေက သုံးရလွယ်ကူပြီး အဆင်ပြေတဲ့ solution ပါ။ AD5641 က 3 mm x 2 mm အရွယ်လေးပဲရှိပြီး၊ SPI interface ပါတဲ့ 14 bit DAC ပါ။ Power supply voltage က 2.7 V ကနေ 5.5 V အထိသုံးနိုင်ပါတယ်။ နမူနာ ဆက်သွယ် မှုတခုကို အောက်မှာ ပြထားပါတယ်။

ဒါကတော့ AD5641 တွေကို သုံးထားတဲ့ channel ၃ ခုပါတဲ့ digital to analog converter လေးပါ။ LPC54102 dual core ARM microcontroller ကိုသုံးပြီး AD5641 သုံးခုကို ပြိုင်တူ control လုပ်တဲ့ နမူနာ code ပါ။

Low Power DC-DC Power Supply

TPS82085 က inductor ပါသူ့ထဲမှာ တခါထဲပါပြီး efficiency မြင့်တဲ့ 3A ထိ ထုတ်ပေးနိုင်တဲ့ step down converter (MicroSiP DC/DC Power Module) တခုပါ။ အဝင်ဗို့ 2.5V ကနေ 6V အထိရပြီး၊ အထွက်ဗို့ 0.8V ကနေ အဝင်နဲ့ ညီတဲ့အထိ adjust လုပ်လို့ရပါတယ်။ အရွယ်အစားက လည်း 3.0-mm x 2.8-mm x 1.3-mm ပဲရှိပြီး 8-Pin ပါတဲ့ Package နဲ့လာပါတယ်။ Switching frequency က 2.4 MHz နဲ့ အလုပ်လုပ်ပါတယ်။

Figure. Pin Functions.

  • EN - Pin 1 က high ဆိုရင် အလုပ်လုပ်မှာ ဖြစ်ပြီး၊ low ပေးထားရင် အလုပ်မလုပ်ပါဘူး။ 400 kΩ internal pull-down resistor ပါပါတယ်။
  • PG - Pin 2 က power good output ပါ။ open drain output pin ဖြစ်ပြီး 1 mA ထိ sink လုပ်ပေးနိုင်ပါတယ်။ အထွက်ဗို့ အမှန်ရဲ့ 95% ကျော် လာပြီဆိုတာနဲ့ high impedance ဖြစ်နေမှာဖြစ်ပါတယ်။ Disable ဖြစ်တဲ့အချိန်၊ thermal shutdown ဖြစ်တဲ့အချိန်၊ အထွက်ဗို့အမှန်ရဲ့ 90% အောက်ထိကျသွားတဲ့ အချိန်တွေမှာဆိုရင်တော့ low ဖြစ်သွားပါမယ်။
  • VIN - Pin 3,4 က အဝင် ဗို့ဆက်ဖို့ပါ။
  • GND - Pin 5,6 က ground ဆက်ဖို့ပါ။
  • FB - Pin 7 က feedback reference အဝင် pin ပါ။ Feedback regulation voltage 800 mV ဖြစ်ပြီး external resisnor divider ဆက်ပြီး လိုချင်တဲ့ အထွက်ဗို့ရအောင် ဆက်နိုင်ပါတယ်။
  • VOUT - Pin 8 က အထွက်ဗို့ပါ။


Figure. 3.6V output application. PG indicator LED can be used only when the output voltage is greater than its forward voltage.

Resistors တွေရဲ့ တန်ဖိုးနဲ့ အထွက်ဗို့ရဲ့ ဆက်သွယ်ချက် ကို အောက်ပါအတိုင်း ဖော်ပြနိုင်ပါတယ်။ $$R1 = R2 . ( VOUT/0.8 - 1 ) $$ အဲဒီမှာ R2 ရဲ့ တန်ဖိုးက 180 kΩ ထက်မကျော်သင့်ဘူးလို့ ဆိုပါတယ်။ ဒါကြောင့် R2 ကို 160 kΩ သုံးလိုက်ရင် R1 တန်ဖိုးက 560 kΩ ရပါတယ်။ အဝင် capacitor ရဲ့ တန်ဖိုးက 10 μF နဲ့ အထက်သုံးနိုင်ပြီး၊ အထွက် capacitor ရဲ့ တန်ဖိုးကတော့ 22 μF နဲ့ 150 μF ကြားမှာရှိဖို့လိုပါတယ်။

Figure. Layout example.

အထွက် current အများကြီး လိုပြီး၊ PCB မှာနေရာ နည်းနည်းပဲ ရှိတဲ့ အခါမျိုးမှာ တော်တော် အဆင်ပြေပါတယ်။ အထွက် current အများကြီး မလိုပဲ၊ အဝင်ဗို့ နည်းနည်းပဲ ရှိတဲ့အခါမျိုး၊ single cell နဲ့ သုံးတဲ့ အခါမျိုးဆိုရင်တော့ TPS61200 တို့၊ LTC3525 တို့နဲ့လည်း အဆင်ပြေပါတယ်။
Reference
http://www.ti.com/lit/ds/symlink/tps82085.pdf

Wednesday, November 25, 2015

CC2531 Zigbee USB Dongle

CC2531 USB Evaluation Module Kit ကိုသုံးပြီး wireless communication လုပ်ကြည့်တဲ့ အကြောင်းလေးပါ။ သူ့ရဲ့ website ကိုသွားပြီး CC USB Firmware Library and Examples ဆိုတဲ့ zip ဖိုင်ကို download လုပ်လိုက်ပါတယ်။ ဖိုင်ကိုဖြည်ပြီးတဲ့ အခါ Doc folder ထဲက CC USB Software Examples User’s Guide ထဲမှာ နမူနာပြထားတဲ့ USB RF Modem Example ကို စမ်းကြည့်ခဲ့ပါတယ်။

CC2531 Zigbee Wireless USB Dongle

Tuesday, November 24, 2015

Wireless Communication using CC2530 Zigbee Wireless MCU

CC2530 က IEEE 802.15.4 နဲ့ Zigbee တွေအတွက် RF transceiver နဲ့ 8051 MCU ကို ပေါင်းစပ်ထားတဲ့ system-on-chip (SoC) solution တခုပါ။ သူ့ကို သုံးပြီး wireless module စမ်းလုပ်ဖို့ အတွက် CC2530EM Evaluation Modules နှစ်ခု၊ SmartRF05EB Evaluation Boards နှစ်ခု၊ နဲ့ CC2531 USB Dongle တခုပါတဲ့ CC2530DK devolopment kit ကို ဝယ်တာ USD 400 လောက်ပေးရပါတယ်။ သူတို့နဲ့ သုံးဖို့အတွက် TI ရဲ့ ဝက်ဘ်ဆိုက်မှာ အလကားပေးတဲ့ SmartRF Studio ကို စက်ထဲမှာ install လုပ်ပါတယ်။

CC2530DK

Tuesday, November 17, 2015

Driving 28BYJ-48-5V Stepper Motor with ULN2003A Transistor Arrays on Arduino

28BYJ-48-5V Stepper Motor နဲ့ ULN2003A driver တွေက တော်တော် အသုံးများပုံရပြီး အလွယ်တကူ ဝယ်နိုင်ရုံတင်မက စျေးလည်း တော်တော်ပေါ ပါတယ်။ Stepper Library ကို မသုံးပဲ Arduino ရဲ့ Port B ကို သုံးပြီး Stepper motor ကို ထိန်းတဲ့ ရိုးရှင်းတဲ့ နမူနာလေး ဖော်ပြချင်ပါတယ်။


Figure. Driving 28BYJ-48-5V Stepper Motor with Arduino UNO using USB power.


28BYJ-48-5V Stepper Motor က 5V နဲ့ တိုက်ရိုက်မောင်းနိုင်ပြီး၊ unipolar stepper motor အမျိုးအစားပါ။ သူ့ရဲ့ schematic ကို အောက်မှာပြထားပါတယ်။


Figure. 28BYJ-48-5V Stepper Motor.


ULN2003A Transistor Arrays ကတော့ inductive load တွေကို drive လုပ်ဖို့ ဒီဇိုင်းလုပ်ထားတာမို့ အထဲမှာ free wheeling diode ပါ ပါ ပါတယ်။ Darlington pair သုံးထားတာမို့ အဝင် ဗို့ 1.4V လောက်ကနေ 30V အထိ ကြိုက်တဲ့ ဗို့နဲ့ တိုက်ရိုက်ဆက်ပြီး ထိန်းနိုင်ပါတယ်။


Figure. ULN2003A.


Wave drive, Full step drive နဲ့ Half step drive တွေကို သုံးပြထားတဲ့ နမူနာ ပရိုဂရမ် လေးကို အောက်မှာ ပြထားပါတယ်။


//Driving 28BYJ-48-5V Stepper Motor using ULN2003A Transistor Arrays
//Author: Yan Naing Aye
//Website: http://www.cool-emerald.com/

#include "StepperPortB.h"
//----------------------------------------------------------
void setup() {    
  StepperInit();//setup pins
  //StepperMode(WAVE);
  //StepperMode(FULL);
  StepperMode(HALF);
  //Serial.begin(9600);
}
void loop() {
  Step(4096,2500); //turn 4096 steps forward with 2500 us period for each step
  Step(-4096,2500);//turn 4096 steps backward with 2500 us period for each step
  //Serial.println(CS);
}


//File: StepperPortB.h
//Author: Yan Naing Aye
//Website: http://www.cool-emerald.com/

//Driving 28BYJ-48 – 5V Stepper Motor using ULN2003A Transistor Arrays
//----------------------------------------------------------
#ifndef StepperPortB_h
  #define StepperPortB_h
  #include "Arduino.h"
byte* S; //Stepping sequence

//Wave drive
//Step          0 | 1 | 2 | 3 | 0 |...

//Blue   = A :  1 | 0 | 0 | 0 | 1 | ...
//Pink   = B :  0 | 1 | 0 | 0 | 0 | ...
//Yellow = C :  0 | 0 | 1 | 0 | 0 | ...
//Orange = D :  0 | 0 | 0 | 1 | 0 | ...
byte Wave[4] = {0x01,0x02,0x04,0x08};

//Full Step drive
//Step          0 | 1 | 2 | 3 | 0 |...

//Blue   = A :  1 | 1 | 0 | 0 | 1 | ...
//Pink   = B :  0 | 1 | 1 | 0 | 0 | ...
//Yellow = C :  0 | 0 | 1 | 1 | 0 | ...
//Orange = D :  1 | 0 | 0 | 1 | 1 | ...  
byte FullStep[4] = {0x09,0x03,0x06,0x0C};

//Half Step drive
//Step          0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 0 |...

//Blue   = A :  1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 1 |...
//Pink   = B :  0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |...
//Yellow = C :  0 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 |...
//Orange = D :  1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |...
byte HalfStep[8] = {0x09,0x01,0x03,0x02,0x06,0x04,0x0C,0x08};
int CS=0;//Current step
int N;
//----------------------------------------------------------
//Mode definition
#define HALF 0
#define FULL 1
#define WAVE 2
//Define the mode to drive the stepper motor
void StepperMode(int Mode) {  
  if(Mode==WAVE) {S=Wave; N=4;}
  else if(Mode==FULL) {S=FullStep; N=4;}
  else {S=HalfStep; N=8;}
}
//----------------------------------------------------------
//Turn stepper motor n steps
//with t microseconds period for each step
//positive n for forward dir and negative n for backward dir
void Step(int n,int t) {
  int CD=1; 
  if(n<0) {n*=-1; CD=-1;}
  for(int i=0;i<n;i++) {
    CS=(CS+(N+CD))%N;
    PORTB=S[CS];
    delayMicroseconds(t);
  }
}
//----------------------------------------------------------
//Initialize
void StepperInit() {
  //Setup port B (digital pin 8 to 13)
  //The two high bits (6 & 7) map to the crystal pins and are not usable
  //only 4 pins - 8 to 11 are used in this program
  //where Blue - pin 8 (LSB), Pink -pin 9, Yellow -pin 10, Orange -pin 11
  DDRB=0xff;
  PORTB = 0x00;  
}
//----------------------------------------------------------
#endif

Monday, November 16, 2015

Fitting a curve to a function

ပေးထားတဲ့ curve တခုနဲ့ အကိုက်ညီဆံုး piecewise linear function တခုကို ရှာတဲ့ နမူနာ MatLab code တခုပါ။



%Fitting a curve to a piecewise linear function using least square method
%with the fixed start and end points

%clear command windows
clc;

%clear workspace
clear all;
%--------------------------------------------------------------------------
%Read curves
load Curve.dat;

%find lower left and upper right corners 
xD=Curve(1,:);
yD=Curve(2,:);
x0=min(xD); x1=max(xD); 
y0=min(yD);  y1=max(yD);
n=5;%order n i.e, the number of segments
FS=x1-x0;
global xs;
global yB;
global yE;
xs=(0:FS/n:FS);
yB=y0;
yE=y1;
%initialize coefficients (y values) to find 
%excluding the first and the last one
ys_initial=xs(2:n);
% options = optimset('MaxFunEvals',1000,'MaxIter',1000);
% LowerBoundC=y0;
% UpperBoundC=y1;
% ys =lsqcurvefit(@LineSeg,ys_initial,xD,yD,LowerBoundC,UpperBoundC,options);
ys =lsqcurvefit(@LineSeg,ys_initial,xD,yD);
%fixed start and end points
ys=[y0 ys y1];
%--------------------------------------------------------------------------
%Plot 
hFig1 = figure(1);
set(hFig1, 'Position', [600 100 500 300])
plot(xD,yD,':g','LineWidth',3,...
                'MarkerEdgeColor','b',...
                'MarkerFaceColor','b',...
                'MarkerSize',2)
hold on;             
plot(xs,ys,'-rs','LineWidth',1,...
     'MarkerEdgeColor','r',...
     'MarkerFaceColor','r',...
     'MarkerSize',4)
hold off;        
grid on;
%--------------------------------------------------------------------------


LineSeg.m
function [y] = LineSeg(ys,x)

global xs
global yB
global yE
L=length(x);
y=zeros(1,L);
ys=[yB ys yE];
LS=length(ys);
for i=1:L
    xt=x(i);
    %--------------------------
    %find segment
    for j=2:LS
        if(xs(j)>=xt) 
            break;
        end
    end    
    %interpolate
    x2=xs(j);
    y2=ys(j);
    y1=ys(j-1);
    x1=xs(j-1);
    y(i)=y1+(y2-y1)/(x2-x1)*(xt-x1);
    %--------------------------
end