Leader

Showing posts with label Data acquisition. Show all posts
Showing posts with label Data acquisition. Show all posts

Saturday, 13 August 2016

Generate sine wave/tone Matlab

Download
genTone.m


How-to
Generating tones or sine waves of specific frequencies in Matlab is conceptually simple, but generating the correct frequency over the correct time period at the correct sampling rate can be a bit confusing at first. This article deals mainly to generating sine wave tones, and genTone.m is designed to simplify this process, but the timing aspects also apply to any signal output from a digital system.


Friday, 19 April 2013

Multiple Velleman K8055D USB Boards in Matlab

Download
K8055_multiple.zip

Containing...
K8055D_connect.m - The main script used to connect to the boards, modified from this article from the hack hole to allow up to four Velleman K8055D boards to interface with matlab. 
K9055D.h and K8055D0-3.dll - files required to connect to the boards.
setdigital.m - script used to set the digital channels on the board to represent a decimal in 8 bit binary
dec2bin2.m -  used in setdigital.m to convert decimal to binary.


Connecting...

K8055D_connect.m
The first line of this function should be edited so that it points to the folder containing the .h and .dll files.

This script accepts a vector input, CardAddress which specifies the addresses of the cards to connect to (0, 1, 2, 3) and returns a list of board it successfully connects to. For example, to connect to four cards in one go:

>>CardAddress=0:3;
>>K8055D_connect(CardAddress) 
ans = 
      0 1 2 3

After connecting a window pops up for each board with possible commands. These can be set to the board using the CALLLIB function, and the .dll for a single board, for example:

>> calllib('K8055D0', 'ClearAllDigital');
Sends the command to clear all the digital channels (set them to 0) for board 0.


setdigital.m
This script takes a decimal as an input, converts it to binary and sets the 8 digital channels on the specified board to a 8-bit binary representation of the decimal. Uses dec2bin2.m. For example,

>> setdigital.m(0,100)
Sets the digital channels on board 0 to represent the number 100 in binary.


AdSense