Search This Blog

Showing posts with label Control. Show all posts
Showing posts with label Control. Show all posts

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 ပါ။

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

Wednesday, February 6, 2013

TRIAC Power Control Circuit

အိမ်က ဖုန်စုပ်စက်လေး ပျက်သွားတော့ ဖျု့စ် ပျက်တာလောက် ဆိုရင် ပြင်လို့ ရရင် ရနိုင်ကောင်းရဲ့ ဆိုပြီး စက်ကို ဖွင့် ဖျု့စ်လိုက်ရှာတော့ မတွေ့ပါဘူး :P။ ပလပ်မှာ လည်း မပါတော့ ဒါ ဆိုရင် ပါဝါ ကွန်ထရိုး လုပ်ပေးတဲ့ ဆားကစ် ကပျက်တာ လည်း ဖြစ်နိုင်တာပဲ ဆို ပြီး အဝင်ကြိုးကို ဆားကစ် ကို မဆက်ပဲ ကျော်ပြီး မော်တာ ကို တိုက်ရိုက် ဆက်ကြည့်ပါတယ်။ ဒါလည်း မလုပ်ပါဘူး။ နောက်ဆုံး တော့ စက် အဟောင်းကို ပစ်ပြီး၊ ဖုန်စက် စက် အသစ် တစ်လုံး ဝယ် ပြီး ဖြေရှင်းလိုက်တယ်။ အေးရော :P။ ပါဝါ ကွန်ထရိုး လုပ်ပေးတဲ့ ဆားကစ် လေးကိုတော့ မပစ်ပဲ အားတဲ့အချိန် trace လိုက်ကြည့်ပါတယ်။ သူက ရိုးရှင်းတဲ့ RC ဆားကစ်လေးနဲ့ DIAC ကိုသုံးပြီး TRIAC ဘယ်လောက် နောက်ကျပြီးမှ ပွင့် မလဲဆိုတဲ့ အချိန်ကို ထိန်းသွားတာပါ။ ဆားကစ်လေးက ရိုးရှင်းပြီး အခြေခံ ကျပါတယ်။ သူ့ကို အောက်ကပုံတွေမှာ ပြထားပါတယ်။