ZEO-S 와 ZEO-IO2 로 8채널 ADC를 모두 사용하는 예제입니다.

 

CDS 8개를 각각 ADC1 ~ ADC8에 연결하고 CDS 밝기에 따라

LED를 ON/OFF 합니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

윈도우 프로그램 화면 – 잠깐 동안 CDS를 가렸다가 뗄 경우

 

 

 

 

 

윈도우 프로그램 – CDS를 순차적으로 가린 경우

 

 

 

 

 

   

코드 C#

 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using ZeoDotNetLib;

using System.Diagnostics;

using System.Threading;

 

namespace ADCTest8CH

{

public partial class Form1 : Form

{

// LED 를 그룹으로 지정

PIN_NAME LED1 = PIN_NAME.PA3 | PIN_NAME.PA4;

PIN_NAME LED2 = PIN_NAME.PA5 | PIN_NAME.PA6;

PIN_NAME LED3 = PIN_NAME.PA7 | PIN_NAME.PA8;

PIN_NAME LED4 = PIN_NAME.PA9 | PIN_NAME.PB12;

PIN_NAME LED5 = PIN_NAME.PB0 | PIN_NAME.PB1;

PIN_NAME LED6 = PIN_NAME.PB2 | PIN_NAME.PB3;

PIN_NAME LED7 = PIN_NAME.PB4 | PIN_NAME.PB5;

PIN_NAME LED8 = PIN_NAME.PB6 | PIN_NAME.PB7;

 

// ZEO용 인스턴스

const int ADC_MEM_SIZE = 0x3C00;

ZeoDotNetLib.ZeoLib ZEO1 = new ZeoDotNetLib.ZeoLib();

 

// 그래픽용

GraphControl GraphCtrl;

 

public Form1()

{

InitializeComponent();

 

this.cboADCSpeed.SelectedIndex = 0;

this.cboReadSpeed.SelectedIndex = 0;

}

 

private void Form1_Load(object sender, EventArgs e)

{

GraphCtrl = new GraphControl(new Font("Arial", 12), new Font("Arial", 10), new Font("Arial", 8));

GraphCtrl.TabIndex = 0;

GraphCtrl.Dock = DockStyle.Fill;

GraphCtrl.Name = "ADC1 ";

 

//Add Graph Control to the form

GraphPanel.Controls.Add(GraphCtrl);

 

//Add series

GraphCtrl.AddPointsSerie("ADC1", Axes.VerticalPrimary, " 1", Color.Red);

GraphCtrl.AddPointsSerie("ADC2", Axes.VerticalPrimary, " 2", Color.Green);

GraphCtrl.AddPointsSerie("ADC3", Axes.VerticalPrimary, " 3", Color.Blue);

GraphCtrl.AddPointsSerie("ADC4", Axes.VerticalPrimary, " 4", Color.DarkBlue);

GraphCtrl.AddPointsSerie("ADC5", Axes.VerticalPrimary, " 5", Color.YellowGreen);

GraphCtrl.AddPointsSerie("ADC6", Axes.VerticalPrimary, " 6", Color.SkyBlue);

GraphCtrl.AddPointsSerie("ADC7", Axes.VerticalPrimary, " 7", Color.Gray);

GraphCtrl.AddPointsSerie("ADC8", Axes.VerticalPrimary, " 8", Color.DarkGreen);

 

GraphCtrl.Invalidate();

 

 

if (FStatus.OK == this.ZEO1.Open())

{

this.ZEO1.InitZeo(ADC_MEM_SIZE);

this.lblBoardInfo.Text = "ZEO-" + this.ZEO1.GetZeroType().ToString() + ", " + this.ZEO1.GetBoardVersion().ToString();

 

this.btnStart.Enabled = this.btnStop.Enabled = true;

this.ZEO1.ADCReceived += new eventADCReceived(ZEO_ADCReceived);

this.ZEO1.Pin_DirOutput(LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7 | LED8);

this.ZEO1.Pin_Reset(LED1 | LED2 | LED3 | LED4 | LED5 | LED6 | LED7 | LED8);

}

else

{

this.lblBoardInfo.Text = "open fail";

this.lblBoardInfo.ForeColor = Color.Red;

}

Thread.Sleep(1000);

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

Thread.Sleep(100);

ZEO1.Close();

}

 

private void btnStart_Click(object sender, EventArgs e)

{

// ADC 8채널 지정

ADCStarter[] _start = new ADCStarter[]{

new ADCStarter(ADCChannel._1,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._2,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._3,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._4,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._5,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._6,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._7,(ADCSpeed1) cboADCSpeed.SelectedIndex),

new ADCStarter(ADCChannel._8,(ADCSpeed1) cboADCSpeed.SelectedIndex),

};

 

this.ZEO1.InitADC1(_start);

this.ZEO1.WaitStandby();

 

}

 

int m_iAdcDiv = 0;

int[] g_iADCData;

 

// ADC 데이터를 받으면

void ZEO_ADCReceived(byte[] bData)

{

 

if (bData == null) return;

if (bData.Length <= 7) return;

 

int iADCChannelCount = this.ZEO1.GetADCChannelCount();

if (iADCChannelCount <= 0) return;

 

UInt16[] uiData = new UInt16[bData.Length / 2];

Buffer.BlockCopy(bData, 0, uiData, 0, bData.Length);

 

g_iADCData = Array.ConvertAll(uiData, new Converter<UInt16, int>(UInt16ToInt32));

 

for (int i = 0; i < g_iADCData.Length; i += (iADCChannelCount * m_iAdcDiv))

{

GraphCtrl.GetPointsSerie("ADC1").AddPoint(g_iADCData[i]);

GraphCtrl.GetPointsSerie("ADC2").AddPoint(g_iADCData[i + 1]);

GraphCtrl.GetPointsSerie("ADC3").AddPoint(g_iADCData[i + 2]);

GraphCtrl.GetPointsSerie("ADC4").AddPoint(g_iADCData[i + 3]);

GraphCtrl.GetPointsSerie("ADC5").AddPoint(g_iADCData[i + 4]);

GraphCtrl.GetPointsSerie("ADC6").AddPoint(g_iADCData[i + 5]);

GraphCtrl.GetPointsSerie("ADC7").AddPoint(g_iADCData[i + 6]);

GraphCtrl.GetPointsSerie("ADC8").AddPoint(g_iADCData[i + 7]);

}

 

// 그래프 refresh

GraphCtrl.Invalidate();

}

 

public static int UInt16ToInt32(UInt16 pf)

{

return Convert.ToInt32(pf);

}

 

private void DisplayResult(string _str)

{

Console.WriteLine(_str);

}

 

private void button2_Click(object sender, EventArgs e)

{

this.ZEO1.DisableADC();

}

 

private void tmrRx_Tick(object sender, EventArgs e)

{

if (g_iADCData == null) return;

 

if (g_iADCData.Length>8)

{

this.ZEO1.Pin_Write(LED1, Convert.ToBoolean(g_iADCData[0] < 750));

this.ZEO1.Pin_Write(LED2, Convert.ToBoolean(g_iADCData[1] < 750));

this.ZEO1.Pin_Write(LED3, Convert.ToBoolean(g_iADCData[2] < 750));

this.ZEO1.Pin_Write(LED4, Convert.ToBoolean(g_iADCData[3] < 750));

this.ZEO1.Pin_Write(LED5, Convert.ToBoolean(g_iADCData[4] < 750));

this.ZEO1.Pin_Write(LED6, Convert.ToBoolean(g_iADCData[5] < 750));

this.ZEO1.Pin_Write(LED7, Convert.ToBoolean(g_iADCData[6] < 750));

this.ZEO1.Pin_Write(LED8, Convert.ToBoolean(g_iADCData[7] < 750));

}

}

 

private void cboReadSpeed_SelectedIndexChanged(object sender, EventArgs e)

{

// 데이터 읽기 간격을 변경하면

m_iAdcDiv = cboReadSpeed.SelectedIndex + 1;

}

 

}

}

 

 

 

 

   

   

전체 코드 Visual C# 2008 용

다운로드

   

출처: http://whiteat.com/bPDS_ZEO/186977 

   

 

 

Posted by WhiteAT
,

 

ZEO-S 모듈의 I/O, ADC, PWM을 실험할 수 있는 보드 입니다.

 

ZEO-S 를 장착하지 않은 상태

 

 

 

 

ZEO-S 를 장착한 상태

 

 

 

ZEO-S 의 연결 핀

 

ZEO-IO2 보드

ZEO-S

CDS

CDS1

PB13*

CDS2

PB14*

CDS3

PB15*

CDS4

PA16*

CDS5

PA15

CDS6

PA14

CDS7

PA13*

CDS8

PA12*

LED

D1

PA3

D2

PA4

D3    

PA5

D4

PA6

D5

PA7

D6

PA8

D7

PA9

D8

PB12

D14

PB0

D15

PB1

D16

PB2

D17

PB3

D18

PB4

D19

PB5

D20

PB6

D21

PB7

SERVO

SERVO1

PA0

SERVO2

PA1

SERVO3

PA2

SERVO4

PA10

SERVO5

PA11

SERVO6

PA12*

SERVO7

PA13*

SERVO8

PA16*

SERVO9

PB13*

SERVO10

PB14*

SERVO11

PB15*

 

* 표시는 ADC 와 PWM 기능이 있는 핀이며 다음과 같이 딥스위치로 선택하여 사용합니다.

 

DIP 스위치

ON

OFF

1

SERVO4 사용

2

SERVO5 사용

3

CDS8 사용

SERVO6 사용

4

CDS7 사용

SERVO7 사용

5

CDS4 사용

SERVO8 사용

6

CDS1 사용

SERVO9 사용

7

CDS2 사용

SERVO10 사용

8

CDS3 사용

SERVO11사용

 

 

원문: http://whiteat.com/Product_ZEO/186932

 

'ZEO 시리즈' 카테고리의 다른 글

ZEO-S, CDS로 빛 밝기 -> LED ON/OFF  (0) 2013.10.30
ZEO-S PWM 펄스를 Pulse Counter로 읽기, C#  (0) 2013.09.02
ZEO-S Pulse Counter, C#  (0) 2013.08.29
ZEO-S, 스위치로 LED ON/OFF, C#  (0) 2013.06.13
ZEO-S, LED 연속으로 이동, C#  (0) 2013.06.08
Posted by WhiteAT
,

 

ZEO-S 의 Pulse Counter 로 스위치 입력을 카운터 해보았습니다. Pulse Counter 로 몇 KHz까지 정확히 읽을 수 있는지 실험해 보겠습니다.

 

ZEO-S 의 PWM (PA11) 과 Pulse Counter (PA12)를 점퍼로 연결합니다. 그러면 PA11의 PWM 출력이 PA12 의 Pulse Counter 로 입력됩니다.

 

 

 

100Khz 의 PWM으로 실험을 진행합니다.

 

 

 

 

 

10초 동안 아래처럼 약 1,000,000 개의 펄스를 입력 받게 됩니다.

 

 

 

 

 

24초 동안 아래처럼 약 24,000,000 개의 펄스를 입력 받게 됩니다.

 

 

 

 

 

 

200Khz 의 PWM에서는 10초 동안 아래처럼 약 2,000,000 개의 펄스를 입력 받게 됩니다.

 

 

200Khz 의 PWM에서도 정확한 카운터를 얻었습니다.

 

 

 

코드 C#

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ZeoDotNetLib;


namespace PulseInputFromPWM
{
  public partial class Form1 : Form
  {
    Double dTotalCnt = 0;
    UInt16 lastCnt = 0;
    ZeoLib ZEO = new ZeoLib();
    int iTmrCnt = 0;

    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      this.ZEO.Open();
      this.ZEO.InitZeo(0);
      this.label1.Text = this.ZEO.ToString();

      this.ZEO.InitCount(7);
     
      // 2Khz 파형 발생
      //this.ZEO.InitPWMC(PWM_Frequency._2Khz, 0, 0, 0, 0);

      // 100Khz 파형 발생
      this.ZEO.InitPWMC(360-1, 0, 0, 0, 0);
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
      this.ZEO.Close();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      this.GetCounts();
      this.lblTmr.Text = (iTmrCnt++/5).ToString()+"초 경과";
    }
 
    public void GetCounts()
    {
      if (!this.ZEO.IsOpened) return;

      UInt16   _cnt = 0;
      this.ZEO.GetCount(7, out _cnt);


      if (_cnt - lastCnt >=0)
        dTotalCnt += (_cnt-lastCnt);
      else
        dTotalCnt += (_cnt - lastCnt)+65536;

      lastCnt = _cnt  ;

      this.lblTotalCount.Text = dTotalCnt.ToString();
 
    }

    private void btnStart_Click(object sender, EventArgs e)
    {
      this.ZEO.UpdatePWMC(2, 200);
      iTmrCnt = 0;
      dTotalCnt = 0;
    }

    private void btnStop_Click(object sender, EventArgs e)
    {
      this.ZEO.UpdatePWMC(2, 0);
    }
 

  }
}

 

 

 

 

DC 모터 구동에 필요한 PWM, 스텝모터 구동에 사용되는 PULSE 도 ZEO-S의 Pulse Counter로 감시하게 되면 동작 유무를 쉽게 판단할 수 있고, 데이터 라인에 연결하여 데이터 전송되는지 체크하는데 사용할 수도 있습니다.

 

 

전체 코드 Visual C# 2008 용

 

 다운로드



  

출처: http://whiteat.com/185984

 

 

 

 

 

'ZEO 시리즈' 카테고리의 다른 글

ZEO-S, CDS로 빛 밝기 -> LED ON/OFF  (0) 2013.10.30
ZEO-IO2 BOARD – ZEO IO 실험 보드2  (0) 2013.10.28
ZEO-S Pulse Counter, C#  (0) 2013.08.29
ZEO-S, 스위치로 LED ON/OFF, C#  (0) 2013.06.13
ZEO-S, LED 연속으로 이동, C#  (0) 2013.06.08
Posted by WhiteAT
,

 

ZEO-S 의 Pulse Counter 기능으로 펄스 카운터를 쉽게 구할 수 있습니다.

이 기능은 엔코더 모터 회전 수를 계산하는데 많이 사용되는데, 여기서는 버튼의 눌림을 예로 들었으며

모터 회전수 계산은 다음에 올리도록 하겠습니다.

 

 

 

 

 

준비

 

ZEO-IO BOARD에 연결하여 0.5초 간격으로 스위치 눌림 횟수를 확인해 보는 예제입니다.

Pulse Counter0, 1, 2, 4, 5, 6 이 사용되며 버튼의 눌림 횟수의 누적 값과 현재 값을 화면에 표시해 보겠습니다.

 

 

 

 

 

ZEO-S 와 스위치의 연결 상태는 아래와 같습니다.

 

스위치

ZEO-S

 

SW2

PA13

 

SW3

PA14

 

SW4

PA15

 

SW6

PB13

 

SW7

PB13

 

SW8

PB14

 

 

 

 

SW, SW3, SW4, SW6, SW7, SW8이 각각 눌린 누적 횟수는 15, 17, 19, 8, 28, 16 이며

0.5초 동안에 눌린 횟수(즉, 변화값 )는 2,5,2,4,5,1 입니다.

 

 

 

 

 

 

 

SW, SW3, SW4, SW6, SW7, SW8이 각각 눌린 누적 횟수는 55, 53, 55, 30, 48, 63 이며

0.5초 동안에 눌린 횟수(즉, 변화값)는 3,5,3,7,6,12 입니다.

 

 

 

 

코드 C#

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
 using System.Text;
using System.Windows.Forms;
using ZeoDotNetLib;

namespace OutputTest1
{
  public partial class Form1 : Form
  {
    ZeoLib ZEO = new ZeoLib();
    UInt16[] cntLast = new UInt16[8];// 카운터 변화량 계산을 위해 최근 값을 저장


    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      this.ZEO.Open();
      this.ZEO.InitZeo(0);
      this.label1.Text = this.ZEO.ToString();

      this.ZEO.InitCount(0);
      this.ZEO.InitCount(1);
      this.ZEO.InitCount(2);
      this.ZEO.InitCount(3);
      this.ZEO.InitCount(4);
      this.ZEO.InitCount(5);
      this.ZEO.InitCount(6);
      this.ZEO.InitCount(7);

    }

 
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
      this.ZEO.Close();
     }

    public void GetCounts()
    {
      if (!this.ZEO.IsOpened) return;

      StringBuilder sb = new StringBuilder();
      UInt16[] _cnt = null;


      // 한번에 하나의 카운터만 읽기 (상황에 맞게 선택 사용)
      //UInt16   _cnt2 = 0;
      //this.ZEO.GetCount(0, out _cnt2);

      // 한번에 모든 카운터 읽기  (상황에 맞게 선택 사용)
      this.ZEO.GetCounts(out _cnt);

      this.lblCount0.Text = _cnt[0].ToString() + ".." + (_cnt[0] - cntLast[0]).ToString() + "";
      this.lblCount1.Text = _cnt[1].ToString() + ".." + (_cnt[1] - cntLast[1]).ToString() + "";
      this.lblCount2.Text = _cnt[2].ToString() + ".." + (_cnt[2] - cntLast[2]).ToString() + ""; ;
      this.lblCount4.Text = _cnt[4].ToString() + ".." + (_cnt[4] - cntLast[4]).ToString() + ""; ;
      this.lblCount5.Text = _cnt[5].ToString() + ".." + (_cnt[5] - cntLast[5]).ToString() + ""; ;
      this.lblCount6.Text = _cnt[6].ToString() + ".." + (_cnt[6] - cntLast[6]).ToString() + ""; ;

      Buffer.BlockCopy(_cnt, 0, this.cntLast, 0, cntLast.Length * 2);
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
      this.GetCounts();
    }
  }
}

 

 

 

 

 

 

 

 

 

 

 

ReadPort() 와 다른 점

 

이 예제를 보면 ReadPort() 를 사용하여 HIGH, LOW 를 비교하여 카운터해도 됩니다. 하지만 ReadPort()를 사용할 경우 정확한 값을 얻기 힘듭니다. 그 이유는 ReadPort()의 경우 호출되는 순간의 상태를 읽는 것이라 빠르게 변하는 모든 값을 읽기가 거의 불가능하기 때문입니다. 예를 들어 1초에 1000번 정도 상태를 읽으려면 1초에 1000번을 읽어야 하는데 ZEO-S에서는 거의 불가능한 일입니다. 이 때는 Pulse Counter 를 사용해야 합니다.

 

Pulse Counter는 1초에 10000번 이상 변하는 상태도 다 읽어 낼 수 있기 때문입니다.

 

  

전체 코드 Visual C# 2008 용

 

 다운로드



  

출처: http://whiteat.com/185922

 

 

Posted by WhiteAT
,

 

 

프로젝트 실행시 아래와 같은 에러가 발생하는 경우가 있습니다.

 

 

 

 

 

'Run Configuration' 에서 Project 를 선택하지 않아서 발생한 에러입니다.

아래처럼 [Browse…]를 눌러 현재 프로젝트를 선택하면 해결 됩니다.

 

 


 

Posted by WhiteAT
,

 

스위치(버튼)의 입력을 받아 LED 를 ON/OFF 하는 예제입니다.

스위치의 눌림 상태에 따라 LED ON 위치가 변경되는 것을 알 수 있습니다.


스위치(버튼)의 눌림 상태를 읽는 방법은 아래 코드와 같이 3가지 방법이 있습니다.



 

 

 

 

 

 

 

 

 

 

 

코드 C#

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using ZeoDotNetLib;

 

namespace WATInputOutput

{

public partial class Form1 : Form

{

#region ZEO-IO Pin Define

const PIN_NAME D1 = PIN_NAME.PA0;

const PIN_NAME D2 = PIN_NAME.PA1;

const PIN_NAME D3 = PIN_NAME.PA2;

const PIN_NAME D4 = PIN_NAME.PA3;

const PIN_NAME D5 = PIN_NAME.PA4;

const PIN_NAME D6 = PIN_NAME.PA5;

const PIN_NAME D7 = PIN_NAME.PA6;

const PIN_NAME D8 = PIN_NAME.PA7;

const PIN_NAME D9 = PIN_NAME.PA8;

const PIN_NAME D10 = PIN_NAME.PA9;

const PIN_NAME D11 = PIN_NAME.PA10;

const PIN_NAME D12 = PIN_NAME.PA11;

const PIN_NAME D13 = PIN_NAME.PA16;

const PIN_NAME D14 = PIN_NAME.PB0;

const PIN_NAME D15 = PIN_NAME.PB1;

const PIN_NAME D16 = PIN_NAME.PB2;

const PIN_NAME D17 = PIN_NAME.PB3;

const PIN_NAME D18 = PIN_NAME.PB4;

const PIN_NAME D19 = PIN_NAME.PB5;

const PIN_NAME D20 = PIN_NAME.PB6;

const PIN_NAME D21 = PIN_NAME.PB7;

const PIN_NAME D22 = PIN_NAME.PB8;

const PIN_NAME D23 = PIN_NAME.PB9;

const PIN_NAME D24 = PIN_NAME.PB10;

const PIN_NAME D25 = PIN_NAME.PB11;

 

 

const PIN_NAME SW1 = PIN_NAME.PA12;

const PIN_NAME SW2 = PIN_NAME.PA13;

const PIN_NAME SW3 = PIN_NAME.PA14;

const PIN_NAME SW4 = PIN_NAME.PA15;

 

const PIN_NAME SW5 = PIN_NAME.PB12;

const PIN_NAME SW6 = PIN_NAME.PB13;

const PIN_NAME SW7 = PIN_NAME.PB14;

const PIN_NAME SW8 = PIN_NAME.PB15;

 

#endregion

 

 

 

PIN_NAME pin1 = D1 | D2| D3;

PIN_NAME pin2 = D4 | D5 | D6;

PIN_NAME pin3 = D7 | D8 | D9;

PIN_NAME pin4 = D10 | D11 | D12 | D13;

PIN_NAME pin5 = D14 | D15 | D17;

PIN_NAME pin6 = D16 | D18 | D19;

PIN_NAME pin7 = D20 | D21 | D22;

PIN_NAME pin8 = D23 | D24 | D25;

 

// ZEO-S 인스턴스

ZeoLib ZEO = new ZeoLib();

 

 

public Form1()

{

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e)

{

// ZEO 초기화

this.ZEO.Open();

if (this.ZEO.IsOpened)

{

this.ZEO.InitZeo(0);

this.ZEO.Pin_Set(this.ZEO.PIN_ALL);

this.ZEO.PORT_DirOutputALL();

// 스위치를 입력으로 설정

this.ZEO.PORT_DirInput(SW1 | SW2 | SW3 | SW4 | SW5 | SW6 | SW7 | SW8 );

}

 

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

// ZEO 닫기

if (this.ZEO.IsOpened)

this.ZEO.Close();

}

 

private void timer1_Tick(object sender, EventArgs e)

{

if (!this.ZEO.IsOpened)

{

Console.WriteLine("ZEO-S 가 연결되어 있지 않습니다.");

return;

}

 

// 모든 포트의 값을 읽어

UInt32[] uiData = this.ZEO.ReadPortAll();

 

//////////////////////////////////////////////////

// 방법1

 

// SW1 눌리면

if (this.ZEO.PA12this.ZEO.Pin_Set(pin1);

else this.ZEO.Pin_Reset(pin1);

 

// SW2 눌리면

if (this.ZEO.PA13this.ZEO.Pin_Set(pin2);

else this.ZEO.Pin_Reset(pin2);

 

// SW3 눌리면

if (this.ZEO.PA14this.ZEO.Pin_Set(pin3);

else this.ZEO.Pin_Reset(pin3);

 

// SW4 눌리면

if (this.ZEO.PA15this.ZEO.Pin_Set(pin4);

else this.ZEO.Pin_Reset(pin4);

 

 

/////////////////////////////////////////////

// 방법2

 

 

// SW5 눌리면

this.ZEO.Pin_Write(pin5this.ZEO.PB12);

 

// SW6 눌리면

this.ZEO.Pin_Write(pin6this.ZEO.PB13);

 

 

//////////////////////////////////////

// 방법3

 

// SW7 눌리면

if ((uiData[1] & 0x4000) == 0x4000) this.ZEO.Pin_Set(pin7);

else this.ZEO.Pin_Reset(pin7);

 

// SW8 눌리면

if ((uiData[1] & 0x8000) == 0x8000) this.ZEO.Pin_Set(pin8);

else this.ZEO.Pin_Reset(pin8);

 

}

}

}

 

 

 

 

전체 코드 Visual C# 2008 용

다운로드

 

출처: http://whiteat.com/163865 

 

 

'ZEO 시리즈' 카테고리의 다른 글

ZEO-S PWM 펄스를 Pulse Counter로 읽기, C#  (0) 2013.09.02
ZEO-S Pulse Counter, C#  (0) 2013.08.29
ZEO-S, LED 연속으로 이동, C#  (0) 2013.06.08
ZEO-S, LED 이동 속도 조절, C#  (0) 2013.06.06
ZEO-S ADC 샘플링 테스트 C#  (0) 2013.04.16
Posted by WhiteAT
,

 

Timer 를 이용하여 LED 를 연속으로 이동하는 예제입니다.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

동영상

 


 

 

 

 

 

코드 C#

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using ZeoDotNetLib;

 

 

namespace ZEO_Flow2

{

public partial class Form1 : Form

{

// LED 상태

int iStatus = 0;

 

// ZEO-S 인스턴스

ZeoLib ZEO = new ZeoLib();

 

 

public Form1()

{

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e)

{

// ZEO 초기화

this.ZEO.Open();

if (this.ZEO.IsOpened)

{

this.ZEO.InitZeo(0);

this.ZEO.PORT_DirOutputALL();

this.ZEO.Pin_Set(this.ZEO.PIN_ALL);

}

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

// ZEO 닫기

if (this.ZEO.IsOpened)

this.ZEO.Close();

}

 

private void timer1_Tick(object sender, EventArgs e)

{

if (!this.ZEO.IsOpened)

{

Console.WriteLine("ZEO-S 가 연결되어 있지 않습니다.");

return;

}

 

switch (iStatus)

{

case 0: this.ZEO.Pin_Reset(PIN_NAME.PA0); break;

case 1: this.ZEO.Pin_Reset(PIN_NAME.PA2); break;

case 2: this.ZEO.Pin_Reset(PIN_NAME.PA4); break;

case 3: this.ZEO.Pin_Reset(PIN_NAME.PA6); break;

 

case 4: this.ZEO.Pin_Set(PIN_NAME.PA0); break;

case 5: this.ZEO.Pin_Reset(PIN_NAME.PA8); break;

case 6: this.ZEO.Pin_Set(PIN_NAME.PA2); break;

case 7: this.ZEO.Pin_Reset(PIN_NAME.PA10); break;

case 8: this.ZEO.Pin_Set(PIN_NAME.PA4); break;

case 9: this.ZEO.Pin_Reset(PIN_NAME.PA16); break;

case 10: this.ZEO.Pin_Set(PIN_NAME.PA6); break;

case 11: this.ZEO.Pin_Reset(PIN_NAME.PA1); break;

 

case 12: this.ZEO.Pin_Set(PIN_NAME.PA8); break;

case 13: this.ZEO.Pin_Reset(PIN_NAME.PA3); break;

case 14: this.ZEO.Pin_Set(PIN_NAME.PA10); break;

case 15: this.ZEO.Pin_Reset(PIN_NAME.PA5); break;

case 16: this.ZEO.Pin_Set(PIN_NAME.PA16); break;

case 17: this.ZEO.Pin_Reset(PIN_NAME.PA7); break;

 

 

case 18: this.ZEO.Pin_Set(PIN_NAME.PA1); break;

case 19: this.ZEO.Pin_Reset(PIN_NAME.PA9); break;

case 20: this.ZEO.Pin_Set(PIN_NAME.PA3); break;

case 21: this.ZEO.Pin_Reset(PIN_NAME.PA11); break;

case 22: this.ZEO.Pin_Set(PIN_NAME.PA5); break;

case 23: this.ZEO.Pin_Reset(PIN_NAME.PB0); break;

 

 

case 24: this.ZEO.Pin_Set(PIN_NAME.PA7); break;

case 25: this.ZEO.Pin_Reset(PIN_NAME.PB2); break;

case 26: this.ZEO.Pin_Set(PIN_NAME.PA9); break;

case 27: this.ZEO.Pin_Reset(PIN_NAME.PB4); break;

case 28: this.ZEO.Pin_Set(PIN_NAME.PA11); break;

case 29: this.ZEO.Pin_Reset(PIN_NAME.PB6); break;

 

case 30: this.ZEO.Pin_Set(PIN_NAME.PB0); break;

case 31: this.ZEO.Pin_Reset(PIN_NAME.PB9); break;

 

case 32: this.ZEO.Pin_Set(PIN_NAME.PB2); break;

case 33: this.ZEO.Pin_Reset(PIN_NAME.PB11); break;

case 34: this.ZEO.Pin_Set(PIN_NAME.PB4); break;

case 35: this.ZEO.Pin_Reset(PIN_NAME.PB1); break;

case 36: this.ZEO.Pin_Set(PIN_NAME.PB6); break;

case 37: this.ZEO.Pin_Reset(PIN_NAME.PB3); break;

case 38: this.ZEO.Pin_Set(PIN_NAME.PB9); break;

case 39: this.ZEO.Pin_Reset(PIN_NAME.PB5); break;

case 40: this.ZEO.Pin_Set(PIN_NAME.PB11); break;

case 41: this.ZEO.Pin_Reset(PIN_NAME.PB7); break;

case 42: this.ZEO.Pin_Set(PIN_NAME.PB1); break;

case 43: this.ZEO.Pin_Reset(PIN_NAME.PB8); break;

case 44: this.ZEO.Pin_Set(PIN_NAME.PB3); break;

case 45: this.ZEO.Pin_Reset(PIN_NAME.PB10); break;

 

case 46: this.ZEO.Pin_Set(PIN_NAME.PB5); break;

case 47: this.ZEO.Pin_Reset(PIN_NAME.PA0); break;

case 48: this.ZEO.Pin_Set(PIN_NAME.PB7); break;

case 49: this.ZEO.Pin_Reset(PIN_NAME.PA2); break;

case 50: this.ZEO.Pin_Set(PIN_NAME.PB8); break;

case 51: this.ZEO.Pin_Reset(PIN_NAME.PA4); break;

case 52: this.ZEO.Pin_Set(PIN_NAME.PB10); break;

default:

iStatus = 2;

 

break;

}

 

iStatus++;

 

}

}

}

 

 

 

전체 코드 Visual C# 2008 용

 

 다운로드



  

출처:  http://docs.whiteat.com/?p=396


'ZEO 시리즈' 카테고리의 다른 글

ZEO-S Pulse Counter, C#  (0) 2013.08.29
ZEO-S, 스위치로 LED ON/OFF, C#  (0) 2013.06.13
ZEO-S, LED 이동 속도 조절, C#  (0) 2013.06.06
ZEO-S ADC 샘플링 테스트 C#  (0) 2013.04.16
ZEO-IO BOARD – ZEO IO 실험 보드  (0) 2013.04.10
Posted by WhiteAT
,

Timer 의 Interval 값을 조정하여 LED 이동속도를 조절하는 예제입니다.

 

 

 

 

 

 

 

 

동영상

 

 


 

 

 

 

코드 C#

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using ZeoDotNetLib;

 

namespace ZEO_Flow

{

public partial class Form1 : Form

{

const int STEP = 25;

int iStatus = 0;

int NowStep = -STEP;

 

PIN_NAME pin1 = PIN_NAME.PA0 | PIN_NAME.PA2| PIN_NAME.PA4 | PIN_NAME.PA6

| PIN_NAME.PA8 | PIN_NAME.PA10 | PIN_NAME.PA16;

PIN_NAME pin2 = PIN_NAME.PA1 | PIN_NAME.PA3 | PIN_NAME.PA5 | PIN_NAME.PA7

| PIN_NAME.PA9 | PIN_NAME.PA11;

PIN_NAME pin3 = PIN_NAME.PB0 | PIN_NAME.PB2 | PIN_NAME.PB4 | PIN_NAME.PB6

| PIN_NAME.PB9 | PIN_NAME.PB11;

PIN_NAME pin4 = PIN_NAME.PB1 | PIN_NAME.PB3 | PIN_NAME.PB5 | PIN_NAME.PB7

| PIN_NAME.PB8 | PIN_NAME.PB10;

 

ZeoLib ZEO = new ZeoLib();

public Form1()

{

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e)

{

this.ZEO.Open();

this.ZEO.InitZeo(0);

this.ZEO.PORT_DirOutputALL();

this.ZEO.Pin_Set(this.ZEO.PIN_ALL);

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

this.ZEO.Close();

}

 

private void timer1_Tick(object sender, EventArgs e)

{

if (timer1.Interval < 200)

{

timer1.Interval += NowStep/10;

}

else

{

timer1.Interval += NowStep;

}

 

if (timer1.Interval < 100)

{

NowStep = STEP;

}

else if (timer1.Interval > 1000)

{

NowStep = -STEP;

}

 

 

Console.WriteLine("int:"+timer1.Interval.ToString() +", nowstep:"+NowStep.ToString() );

 

switch (iStatus)

{

case 0:

this.ZEO.Pin_Reset(pin1);

this.ZEO.Pin_Set(pin4);

break;

case 1:

this.ZEO.Pin_Reset(pin2);

this.ZEO.Pin_Set(pin1);

 

break;

case 2:

this.ZEO.Pin_Reset(pin3);

this.ZEO.Pin_Set(pin2);

break;

case 3:

this.ZEO.Pin_Reset(pin4);

this.ZEO.Pin_Set(pin3);

break;

default:

break;

}

 

iStatus = (++iStatus)%4;

}

}

}

 

 

 

전체 코드 Visual C# 2008 용


 다운로드




출처: http://whiteat.com/154626



 

'ZEO 시리즈' 카테고리의 다른 글

ZEO-S, 스위치로 LED ON/OFF, C#  (0) 2013.06.13
ZEO-S, LED 연속으로 이동, C#  (0) 2013.06.08
ZEO-S ADC 샘플링 테스트 C#  (0) 2013.04.16
ZEO-IO BOARD – ZEO IO 실험 보드  (0) 2013.04.10
ZEO-S 모듈로 서보모터 제어  (0) 2012.11.16
Posted by WhiteAT
,

 

준비

 

- 프로그램 설치: http://whiteat.com/260

(WinAVR, AVRStudio 가 설치되어 있어야 ATMEGA128에 프로그램을 할 수 있습니다.)

 

- 프로그램 라이팅 방법: 다운로드

(직접 작성한 프로그램을 ATMEGA128 에 라이팅 하는 방법입니다.)

 

- ATMEGA128 초급 키트 (http://kit128.com/goods/view.php?seq=57 )

 

 

 

 

 

 

LED 회전 ON/OFF

 

PORTE에 연결된 8개의 LED 가 ON/OFF 하면서 시계방향으로 회전하는 예제입니다.

이 예제는 EX_01_01과 동일합니다. (http://whiteat.com/57204 참조)

 

/*

EX_01_01.c

 

PORTE에연결된LED 순차적으로ON 하기

 

AVRStudio 4.18

2012-01-08

 

홈페이지: http://whiteat.com

MCU자료실: http://avr128.com

쇼핑몰: http://kit128.com

 

*/

 

#include <avr/io.h>

 

// 일정시간딜레이(약1초)

void Delay()

{

    register unsigned long i;

    for(i = 0; i < 300000; i++)

    {

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");    

    }

}

 

int main()

{

    DDRE = 0xFF; // ALL OUTPUT

    PORTE = 0xFE;    // PORTE.0 LED ON

 

    while(1)

    {

        Delay();

 

        if(PORTE == 0x7F)    // 마지막LED 가ON 되었다면.

        {

            // 처음LED ON 되게

            PORTE = 0xFE;    // PORTE.0 LED ON

        }

        else                // 그렇지않다면

        {

            PORTE <<= 1;    // 한칸이동(PORTE = PORTE<<1; 와동일)

            PORTE |= 1;     // 마지막LED 는OFF (PORTE = PORTE | 0x01; 와동일)

        }

    }

}

 

 

 

 


 

 

 

 

 

 

 

 

 

LED 반복 ON/OFF

 

PORTA에 연결된 8개의 LED 를 교대로 ON/OFF 하는 예제입니다.

 

#include <avr/io.h>

 

// 일정시간딜레이(약초)

void Delay()

{

    register unsigned long i;

    for(i = 0; i < 300000; i++)

    {

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

        asm volatile(" POP R0 ");

        asm volatile(" PUSH R0 ");

     asm volatile(" POP R0 ");    

    }

}

 

int main()

{

    DDRA = 0xFF;

    PORTA = 0x55; // 0, 2, 4, 6 bit LED OFF

 

 

    while(1)

    {

        PORTA = 0x55; // 0, 2, 4, 6 bit LED OFF

         Delay();

 

        PORTA = 0xAA; // 1, 3, 5, 7 bit LED OFF

        Delay();

 

    }

}

 

 

 

 

 

 




 

ATMEGA128 로 LED 를 ON/OFF 하는 예제를 다루어 보았습니다.

 

감사합니다.

 

Posted by WhiteAT
,

도구바, OrCAD Capture

OrCAD 2013. 5. 29. 17:57

 

도구바는 크게 2가지로 나뉘고 각각 메뉴 아래의 [Toolbar]와 우측의 [Tool Palette Bar]입니다.

도구바의 사용 빈도는 사용자마다 다 다르기 때문에 여기서는 간략한 설명만 하겠으며 익숙해 지기 위해서는 많이 사용해 보는 수 밖에 없습니다.

 

 

상단의 [Toolbar]를 순서대로 설명하겠습니다.

  • NEW: 새로운 프로젝트나 새로운 스케메틱 등 새로운 것을 만들 때 사용
  • OPEN: 불러오기
  • SAVE: 저장하기
  • PRINT: 프린트하기
  • CUT: 잘라내기
  • COPY: 복사하기
  • PASTE: 붙여 넣기
  • UNDO: 취소하기
  • REDO: 취소한 거 되돌리기
  • MRU window [Most Recent Used]: 최근 사용한 부품들을 다시 선택하는 것을 도와줍니다.
  • Zoom IN: 윈도우 확대하기
  • Zoom OUT: 윈도우 축소하기
  • Zoom to region: 윈도우 설정영역만 보기
  • Zoom to All: 윈도우를 현재 화면에 맞게 설정하기
  • Annotate (Update Part Reference): 부품의 참조명칭(UNIT NAME) 설정
  • Back Annotate: 스왑파일에 의해 부품번호, 게이트, 그리고 핀을 일괄적으로 변경합니다. 파일 확장명는 SWP
  • Design Rules Check (DRC): 회로도의 디자인 규칙 위반사항 검사(에러가 발생되면 찾아 수정해야 합니다.)
  • Create Netlist: 회로도의 부품과 선 연결정보 file 작성 (여러 가지 포맷 제공)
  • Cross Reference Part: 회로도의 부품 사용 경로와 각 정보를 보고서 형식으로 작성
  • Bill of materials: 회로도에 사용된 부품의 개수, 종류, 수량, 부품 값 등을 보고서 형식으로 작성

 

'OrCAD' 카테고리의 다른 글

단축키, Orcad Capture  (0) 2013.05.29
Tool palette bar, OrCAD Capture for Windows  (0) 2013.05.16
OrCAD Capture for Windows [Option menu]  (0) 2013.03.30
OrCAD Capture for Windows  (0) 2013.03.18
OrCAD 파일 정보  (0) 2013.02.24
Posted by WhiteAT
,