Showing posts with label Microcontroller. Show all posts
Showing posts with label Microcontroller. Show all posts

Friday, January 22, 2010

โหลดหนังสือฟรี

พอดีไปเจอลิงค์ที่รวมแหล่ง Download หนังสือฟรีๆ ความจริงมันก็ไม่ค่อยถูกต้องเท่าไหร่เพราะเป็นหนังสือลิขสิทธิ์ซะส่วนใหญ่ แต่ก็ถือว่าโหลดมาดูก่อนจะซื้อหนังสือมาอ่านก็แล้วกันครับ เพราะยังไงๆอ่านจาก Computer มันก็ไม่มันส์เท่าอ่านจากหนังสือจริงๆหรอก ..รึจะเถียง..;) อีกอย่างถ้าจะหามันก็หาได้ง่ายๆจาก google อยู่แล้ว ไม่ต้องรอให้ punkky มาบอกหร๊อก..

โอเช..ไปที่นี่เลย http://bit.ly/796EaX

Sunday, October 25, 2009

ชิ้นส่วนที่รออยู่

รอของที่ยังไม่ได้สั่ง
1. PIC16F883 SSOP28 ต้องสั่งจาก farnell หรือไม่ก็ Mouser
มีแค่นี้

Friday, November 14, 2008

วงจรจับเวลา 99 วินาที ใช้ Microcontroller

โดยส่วนตัวชอบนาฬิกาที่จับเวลาได้เป็นหลักอยู่แล้ว นาฬิกาที่สะสมส่วนมากจะเป็นนาฬิกาแบบนี้ พอดีเขียน Blog ที่วิชาการ.คอมเกี่ยวกับวิธีทำนาฬิกา ซึ่งได้ยกวงจรจับเวลา 99 วินาทีนี้เป็นตัวอย่างในการทำความเข้าใจ ซึ่ง จุดเด่นของวงจรนี้คือ ไม่มีปุ่มกดจับเวลา หรือว่า หยุดจับเวลา และก็ไม่มีปุ่ม Reset อิ อิ :)
วงจรเป็นดังรูปข้างล่างนี้
99 Second Timer Counter Chronograph

ส่วนโปรแกรมที่เป็นภาษาซี เขียนด้วย MikroC ก็เป็นดังข้างล่างนี้ครับ
//PIC16F627A
//4MHz Internal OSC
// Two Digit Counter
// 13/11/2008
// Punkky@gmail.com
#define Digit1 PORTA.F0
#define Digit2 PORTA.F1

unsigned short tick;
unsigned short x1;
unsigned short x2;
void interrupt () //Interrupt จะถูกเรียกทุกครั้งที่ Timer1 เกิดการ Overflow นั่นคือจะถูกเรียกทุกวินาทีนั่นเอง
{ 
        PIR1.TMR1IF = 0;        // clears TMR1IF
        TMR1H = 0x80; //ตั้งค่าเริ่มต้นของ Timer1 เป็น 0x8000 โดยตั้งเฉพาะสองบิตแรก
        tick = 1; //tick เป็น 1 ทุก 1 วินาที
}

void main(){ 
  CMCON = 0x07;   //Digital I/O for PORTA
  TRISA = 0x00;
  PORTA = 0x00;
  TRISB = 0x00;
  PORTB = 0x00; 
  T1CON = 0x0F; 
         
  // Prescaler 1:1   external clock 
  PIE1.TMR1IE = 1;  // enable interupt to start the clock 
  INTCON = 0xC0;   // Set GIE, PEIE 
  TMR1L = 0x00; 
  TMR1H = 0x80; 
  PCON.OSCF = 1; //Internal Clock 4MHz 
  x1 = 0; //หลักสิบของวินาที 
  x2 = 0; //หลักหน่วยของวินาที
  tick = 0;

  while(1){
    if(tick){ //เมื่อเวลาผ่านไป 1 วินาที ค่า tick จะเป็น 1
       tick = 0;
       x2++; //เพิ่มหลักหน่วยของวินาทีขึ้น 1
       if(x2>9){ //ถ้าหลักหน่วยมากกว่า เก้า ก็ให้เซ็ตเป็น ศูนย์ และนับหลักสิบขึ้น 1
          x2 =0;
          x1++;
          if(x1>9){ //ถ้าหลักสิบมากกว่า เก้า ก็ให้เซ็ตเป็น ศูนย์ เพื่อกลับไปนับจาก 00 ใหม่
             x1 = 0;
          }
          PORTB = x1; //นำค่าของหลักสิบไปแสดงผล
          Digit1 = 1; //สั่งให้ CD4543 นำข้อมูลจาก PORTB ไปแสดงบน 7-Segment
          Digit1 = 0; //สั่งให้ CD4543 คงค่าของตัวเลขไว้ โดยไม่ต้องสนใจค่าของ PORTB อีก
       }
       PORTB = x2; //นำค่าของหลักหน่วยไปแสดงผล
       Digit2 = 1; //สั่งให้ CD4543 นำข้อมูลจาก PORTB ไปแสดงบน 7-Segment
       Digit2 = 0; //สั่งให้ CD4543 คงค่าของตัวเลขไว้ โดยไม่ต้องสนใจค่าของ PORTB อีก
   }
  }
}


จำลองการทำงานด้วย Proteus ได้ตามภาพข้างล่าง
Simulation of 99 second counter timer

Saturday, November 08, 2008

ทำนาฬิกา Digital เล่นๆ (นาฬิกาจริงๆ ไม่ใช่ Flash)

ไปเขียนวิธีทำนาฬิกา Digital เอาไว้ที่
นาฬิกา Digital ทำเองได้ ยังไม่เสร็จ เอามาแปะไว้ก่อน :)

รูปหน้านาฬิกาที่จะทำก็ประมาณนี้
นาฬิกา Digital ทำเอง

Saturday, October 11, 2008

นาฬิกาทำเองหลายๆแบบ My Digital Clock Collection

Hobby ใหม่อันนึงเพิ่มเริ่มได้ไม่นานคือ ทำนาฬิกาอิเล็คทรอนิคส์เล่น เริ่มจากความต้องการนาฬิกาตรงมากๆเพื่อมาให้เป็นเวลาอ้างอิงในการตั้งนาฬิกาและอื่นๆ ทำไปทำมาตอนนี้ก็มีอยู่หลายอันเน้นที่การใช้การแสดงผลด้วยอุปกรณ์ต่างๆกัน นาฬิกาที่ทำมาเป็นในรูปแบบ Prototype คือเป็นบอร์ดแล้วโยงสายไฟเอา ยังไม่ได้ทำลงกล่องสวยงามอะไร บางอันก็แยกชิ้นส่วนไปเป็นเรือนใหม่ๆ วันนี้เอารูปที่เคยถ่ายไว้มาให้ดูกัน
อันนี้เรือนแรกที่เริ่มทำ



อันนี้เป็นนาฬิกาที่ใช้ฐานเวลาจากดาวเทียม GPS ความเที่ยงตรงสุดยอดระดับนาฬิกาอะตอมครับ ใช้จอ LCD แสดงผล ตัวนี้ผมกำลังจะ upgrade จอไปเป็นจอแบบ OLED ที่สวยกว่า ได้จอมาแล้วแต่ยังไม่มีเวลาทำครับ นาฬิกาจะแสดง เวลา วัน วันที่ และจำนวนดาวเทียมที่เห็นตอนนี้ จริงๆแล้วได้ข้อมูล ละติจูด และ ลองจิจูด มาด้วย น่าจะคำนวณ Moon Phase (ข้างขึ้นข้างแรม),พวกน้ำขึ้นนำลง และ equation of time ได้ เอาไว้ทำเป็นโปรเจ็คต่อๆไปครับ



อันนี้ใช้จอ HDSP-211x ของ HP เป็นจอ Vintage ตอนนี้แค่จอนี้ตัวใหม่ก็หลายพันบาทครับ แสดงผลสีเหลืองสวยดี ตัวเลขแสดงเวลาจะวิ่งผ่านหน้าจอทุก 5 วินาที จออันนี้ตอนแรกผมว่าจะเอามาทำนาฬิกาข้อมือ แต่ติดปัญหาเรื่องกินไฟมาก 



อันนี้ล่าสุด เป็นจอแบบ Led Dot Matrix ขนาด 8x8 จุด ขนาดประมาณ 2x2cm ใช้แสดงเวลาโดยเวลาจะวิ่งผ่านหน้าจอไปช้าๆ ตอนนี้ผมเพิ่งสั่งอันใหม่ขนาดจิ๋วทำตัวเลขสูงประมาณ 3mm ไป น่าจะได้นาฬิกาที่เล็กดี



เวลาแสดงผลมันก็วิ่งแบบนี้แหละครับ

เทียบขนาดของ HDSP กับ Led Dot Matrix 8x8 และ Project I


ทีนี้มาดูความเที่ยงตรงของนาฬิกาพวกนี้กัน นาฬิกาที่ผมทำนี้ใช้ตัว Crystal (หรือว่า Quartz นั่นเอง) ในการกำเนิดความถี่ (ยกเว้นตัว GPS clock ที่รับความถี่จากดาวเทียมโดยตรง) ความเที่ยงตรงตาม specของมันอยู่ที่ บวกลบ 1.5 วินาทีต่อวัน เท่าที่ผมลองวัดดูก็อยู่ประมาณนั้นแหละ ตัว Crystal ที่ใช้เป็นของ CITIZEN ครับ หน้าตาแบบนี้แหละ


แกะนาฬิกาข้อมือ(Quartz)ออกดูก็จะเห็นตัวประมาณนี้อยู่ในเครื่องนาฬิกา ซึ่งความเที่ยงตรงระดับนี้ผมยังไม่พอใจเพราะมันยังผิดเป็นนาทีถ้าวางทิ้งไว้เป็นปี ลองหาๆดูก็เจอ Crystal ที่มันเที่ยงตรงมากแบบผิดไปประมาณไม่กี่วินาทีในหนึ่งปี แต่ราคามันก็เอาเรื่อง (ตัวนึงเป็นหมื่น) ผมคงไม่เอามาลองหรอกครับมันแพงเกิน

นาฬิกาพวกนี้ผมทำแบบมือสมัครเล่น ดังนั้นท่านที่เป็นมืออาชีพด้านอิเล็กทรอนิสค์โดยตรงก็กรุณาชี้แนะด้วยครับ
ขอบคุณที่เข้ามาอ่านครับ

Saturday, October 04, 2008

5x7 Led Dot Matrix ใช้ Microcontroller ตัวเดียว

ทำไว้สักพักนึงแล้ว นาฬิกาใช้ 5x7 Led Dot Matrix ตัวเล็กๆตัวนึงกับ Microcontroller PIC16F887 ตัวนึงไม่ถึงร้อยถูกกว่าตัว PIC16F877 ซึ่งตัวนึงสองร้อยกว่าบาทตั้งเยอะแถมยังมี Internal Oscillator 4MHz, 8MHz อีกด้วย ใช้แทนกันได้แทบทันทีเพราะขาก็เรียงเหมือนกัน แต่ยังไงก็ตามต้องดู Datasheet เพื่อความแน่ใจอีกครั้งถ้าจะใช้แทนกัน

สำหรับนาฬิกานี้ใช้ปุ่มสองปุ่มในการตั้งเวลา ถ้าใครสนใจอยากทำก็ส่ง comment ด้วยครับ จะได้เอารายละเอียดวิธีทำมาลงในนี้

Saturday, September 06, 2008

Microcontroller

ตอนนี้ไม่รู้เป็นไรบ้า PIC Microcontroller มาก ทำนาฬิกาออกมาหลายอันแล้ว รายละเอียดเอาไปแปะไว้ที่ http://picnote.blogspot.com และจะมาแปะที่นี่ด้วย โปรดติดตามครับผม :)

Tuesday, June 03, 2008

WDT: Watchdog Timer

I am now addicted to PIC Microcontroller projects. Last week, I just completed a prototype of my GPS controlled digital clock. The clock was running very nice and ,of course, it is one of the most accurate clock in the country :). I was very happy with it and thinking of putting more features to the clock. But... when I saw the clock this morning, I was shocked!. The clock was not running! it stopped last night around 00:23:xx . So, I pressed the reset button and the clock came back. Now, it is running happily (waiting for another Freeze in the future :p )

But, there are some questions. Why my clock stopped? Will it happend again? How to overcome the problem?. After google around, I think I found a potential answers to the questions. I was thinking that microcontrollers are just electronics devices that will work as they promise as long as you provide power to them. But, I was wrong. PIC Microcontrollers can Hang Up or Freeze just like your computers. So, my clock can Freeze just like my PC :) .

Will it happend again?
Yes, it will happend again but nobody knows when.

How to overcome the problem?
Now, the hero is WDT or Watchdog Timer. It just like a dog who keeps comming to see the PIC every certain period of time. If the PIC can kick the dog (by clearing WDT register with CLRWDT command), the dog will go back and will come to see the PIC again next time. But if the PIC cannot kick the dog (the PIC is engaging infinity loop or just freezing), the dog will reset the PIC. One nice thing is that you don't have to wait until the dog comes before you can can kick it. You can kick the dog anytime you want but you have to make sure that you kick it before it resets the PIC. By using WDT, I think I can make my clock running helthly without human reset when it hang up.

How to use WDT?
I am no expert on PIC. So, I will show what I did and explain what I understand.

  1. Set CONFIG word to enable WDT

  2. I use mikroC compiler, so I uncheck the default WDT_OFF = $3FFB and check _WDT_ON = $3FFF

  3. In the code I set up 2 functions: FeedDog() and KickDog()


  4. void FeedDog(){ //Setting WDT
    OPTION_REG = 0x0F; //0b00001111 = Prescalar 1:128 .. reset every 2.3 sec. please consult data sheet for other presacalars
    asm{CLRWDT} //Clear WDT
    }

    void KickDog(){
    asm{ CLRWDT } //Clear WDT before the dog resets the PIC
    }

  5. Placing FeedDog() and KickDog() in the main program

  6. I put FeedDog() around the begining of the program to set up WDT and put KickDog() wherever I think the dog will come. If the program is very long, I can put KickDog() in many places as I want if I think the dog will come after that line of code. It is upto me to calculate where to put the KickDog(). In my case, the dog keeps comming every 2.3 sec so I have to kick the dog before 2.3 sec after each kick. My clock update every second, so if it freeze and cannot kick the dog in 2.3 sec the PIC will be reset.
    Putting KickDog() in the wrong place can make your program running incorrectly. Please be careful.

    void main(){
    .. Set up program ..
    FeedDog();
    .. Set up some more things..

    while(1){
    ...
    .. Do tasks ..
    KickDog();
    ...Do tasks..
    ....
    }

    }


To be revised with images and more details