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
,

 

스위치(버튼)의 입력을 받아 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
,

 

ZEO-S 로 ADC 을 실험해 보겠습니다.

 

 

 

준비

 

먼저 ZEO-S 의 PB13 핀에 360hz 파형을 입력으로 합니다.

(360hz 파형은 Function Generator 를 이용하시거나 DAC 기능이 있는 MCU 로 만들 수 있습니다. )

 

 

 

 

 

분석 1

 

47.619Khz 로 샘플링을 하면 아래와 같이 됩니다.

 

 

 

 

그래프의 397 픽셀 동안 3개의 파형이 발생합니다.

즉 1주기는 약 132 픽셀에 나타납니다.

 

47.619 Khz / 132 는 약 360 Hz 로 계산됩니다.

 

360Hz 의 파형을 47.619 Khz로 정확히 샘플링 합니다.

 

 

 

 

 

 

 

 

분석 2

 

142.857 Khz 로 샘플링을 하면 아래와 같이 됩니다.

 

 

 

그래프의 397 픽셀 동안 1개의 파형이 발생합니다.

즉 1주기는 약 397 픽셀에 나타납니다.

 

142.857 Khz / 397 는 약 360 Hz 로 계산됩니다.

 

360Hz 의 파형을 142.857 Khz로 정확히 샘플링 합니다.

 

 

 

 

 

 

 

분석 3

 

176.470 Khz 로 샘플링을 하면 아래와 같이 됩니다.

 

 

 

 

 

그래프의 490 픽셀 동안 1개의 파형이 발생합니다.

즉 1주기는 약 490 픽셀에 나타납니다.

 

176.470 Khz / 490 는 약 360 Hz 로 계산됩니다.

 

360Hz 의 파형을 176.470 Khz로 정확히 샘플링 합니다.

 

 

 

 

 

 

 

분석 4

 

142.857 Khz 로 샘플링을 하면 아래와 같이 됩니다.

 

 

 

그래프의 397 픽셀 동안 1개의 파형이 발생합니다.

즉 1주기는 약 397 픽셀에 나타납니다.

 

142.857 Khz / 397 는 약 360 Hz 로 계산됩니다.

 

360Hz 의 파형을 142.857 Khz로 정확히 샘플링 합니다.

 

 

 

 

 

분석 3

 

222.222 Khz 로 샘플링을 하면 아래와 같이 됩니다.

 

 

 

 

 

그래프의 617 픽셀 동안 1개의 파형이 발생합니다.

즉 1주기는 약 617 픽셀에 나타납니다.

 

222.222 Khz / 617 는 약 360 Hz 로 계산됩니다.

 

 

360Hz 의 파형을 222.222 Khz로 샘플링하게 되면 손실데이터가 발생하는데, 이는

ZEO-S 에 있는 ADC 데이터를 컴퓨터에서 빠르게 가져오지 못해 발생하는 겁니다.

(위 그림에서는 2151개의 손실 데이터 발생)

 

이 문제를 해결할 수 있는 방법이 몇 가지 있습니다.

  • 컴퓨터 하드웨어 업그레이드
  • ZEO 용 응용 프로그램 외 모든 프로세스 종료(특히 인터넷, 백신)
  • 메모리가 큰 ZEO-M 으로 대체

 

 

ZEO-S 의 빠른 ADC 데이터 처리는 컴퓨터 사양에 큰 영향을 받습니다.

손실된 데이터 값을 잘 체크하여 최대의 샘플링 주기를 찾으셔야 합니다.

 

 

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

 



Posted by WhiteAT
,

 

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

INPUT, OUTPUT, PWM 등을 실험할 수 있습니다.

 

 

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

 

 

 

 

ZEO-S 를 장착한 상태

 

 

 

ZEO-S 의 연결 핀

 

IO 보드

ZEO-S

스위치

SW1

PA12

SW2

PA13

SW3

PA14

SW4

PA15

SW5

PB12

SW6

PB13

SW7

PB14

SW8

PB15

LED

D1

PA0

D2

PA1

D3    

PA2

D4

PA3

D5

PA4

D6

PA5

D7

PA6

D8

PA7

D9

PA8

D10

PA9

D11

PA10

D12

PA11

D13

PA16

D14

PB0

D15

PB1

D16

PB2

D17

PB3

D18

PB4

D19

PB5

D20

PB6

D21

PB7

D22

PB8

D23

PB9

D24

D25

PB10

PB11

 

 

 

 

 

원문: http://whiteat.com/87092 

 

Posted by WhiteAT
,

WAT-AVR128_PLUS 모듈

AVR키트 2013. 4. 8. 17:21




WAT-AVR128 모듈과
확장 보드의 기능을 합친 모듈 입니다.



WAT-AVR128 보드 얼.pdf

WATAVR128_manual.pdf

AVR128 모듈을 다른 보드에 연결하여 사용할수 있는 확장 보드입니다.



PORTA,
PORTB,
PORTC,
PORTD,
PORTE,
PORTF

등의 포트를 다른 보드와 연결해서 사용할 수 있습니다.

 

 

 

 

 

 

 

 

쇼핑몰에서 구매하기

 

 

 

 

 

Posted by WhiteAT
,