Question

Hi  

With the waveforms tool is it possible using python scripting in the Waveforms platform to do  the following ??

Use the Digilent Analogue discovery 2

-   Attach a device like a PMOD device  eg accelerometer  https://store.digilentinc.com/pmod-acl-3-axis-accelerometer/
    using the Analogue discovery 2 ability to chat  SPI & IC2
    
-   pmod DEVICES SUPPORT  12-pin Pmod connector with SPI interface and 2×4-pin I²C interface

-   Then using the read information from the PMOD device treat it like an extra oscilloscope channel .
    Either as a Analog channel or Digital channel depending on the the signal type acquired from the PMOD device.
    
This is possible with Labview but that would also require a lot of code writing.    


If this is possible this is outstanding feature when considering all the available PMOD devices available from the list
https://store.digilentinc.com/by-function/input/

This would be a real product enhancement for Digilent and the Analog Discovery and help sell the AD2 in to many new
places . 

Best wishes

Simon

Share this post


Link to post
Share on other sites

18 answers to this question

Recommended Posts

  • 0

Hi 

I think I have found the answer already maybe 

https://blog.digilentinc.com/capturing-and-analyzing-live-audio/

https://testandmeasure.org/#/category/scripts/pmod-mic3-audio-streaming-recording-125baaaf

These examples show a microphone which is read by SPI . and the result is displayed on the scope screen as channel ref 1 

It would not be so big a step to modify the code to read a  SPI accelerometer .

 

Maybe you even have and example which is already for reading a PMOD accelerometer. 

 

Best wishes 

Simon

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @sib

You can find script examples in Protocol tool/ SPI-I2C Custom and Sensor tabs.

image.png.a9b16187881ffb78a8bd41cfa715ff8d.png

You can also find SPI/I2C examples in the SDK:

image.png.c32bd5192e52f79e46036034f8d2eef7.png

 

Edited by attila

Share this post


Link to post
Share on other sites
  • 0

Hi Attila 

Thank you for showing me the example all that is missing is the pin connections between the PMOD ACL2 and the Digilent AD2

This is the pin out of the PMOD ACL2

image.png.0a659dd793d833112cb68eddf2ccfbd2.png

 

This the pin out for the Digilent AD2 example you showed me 

image.png.95da2c63906ce0ed0be41bfbfe9e9595.png

 

So the pin map can see so far is 

PMOD_ACL5_PIN1 --> ~CS --> AD2_Digital_DIO_0
PMOD_ACL5_PIN4 --> SCLK --> AD2_Digital_DIO_1

PMOD_ACL5_PIN11--> GND --> AD2_V-Power_Supply
PMOD_ACL5_PIN12--> VCC --> AD2_V+Power_Supply

This still leaves 

    AD2_Digital_DIO_2
    AD2_Digital_DIO_3
    AD2_Digital_DIO_4
    AD2_Digital_DIO_5

Which pins do these 4 Analog Discovery ports , connect to which signals on to the PMOD_ACL5 board ?

Best wishes

Simon

Share this post


Link to post
Share on other sites
  • 0

Hi @sib

You should have:
CS to Select, SCLK to Clock, MOSI to DQ0,  MISO to DQ1
Pin-5 or 11 to GND and Pin-6 or 12 to V+ 3.3V

The other interrupt pins and DQ2-3 are not required.

You can find info about the Pmods at:
https://reference.digilentinc.com/reference/pmod/pmodacl/start
https://reference.digilentinc.com/reference/pmod/pmodacl2/start

Share this post


Link to post
Share on other sites
  • 0

Hi Attila 

Thank you for the update. This info should have been in the Digilent AD2 dcoumentation.

This is a summary for any other user who may wish to hook up a Digilent PMOD ACL2 to the Digilent Analog Discovery 2. 

So that all the info is one easy to use post. 

image.thumb.png.eb6ab0b91f468301b2b0e421da113697.png

Share this post


Link to post
Share on other sites
  • 0

Hi Attila 

All the pieces have arrived in the post  . I have assembled the set up. But no working communications.

The set up as a below. Text book setup between Digilent Analog Discovery 2 and PMOD ACL5. Its is UHD photo so you can really zoom in to 

see which wire goes where and there is a wiring diagram and the voltmeter is  attached across the PSU wires PIN GND-PIN5  , VCC3V3 PIN6

Digilent_AD_wired_setup_2.thumb.jpg.d2a50bc2e1ae7924cecbf2c2e44ecbdb.jpg

Below is the output from Digilent Analogue Discovery 2 using waveforms 

As you will notice . It is not working .  The return result from running the example script you suggested for the PMOD-ACL2 return the message "Device ID mismatch"

Digilent_AD2_setup.thumb.png.5f495cefffa42c9658c10733d357607f.png

 

So my question to you is the following 

- 1) Build the set up yourself in your office they are after all Digilent components. Properly test the solution.

- 2) Put up a good post showing all the components working together 

- 3) makes sure you post the newly updated correct working python script.

- 4) Add a proper connection diagram between the PMOD ACL2 and the Analogue Discovery 2 . It was a bit poor this was not include in the AD2 or the PMOD ACL2 document.

Basically this should just work out of the box without issues .

Best wishes

Simon

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @sib

Thank you for the photo and screenshot. The wiring looks good.
At the moment I can't find ACL2, only ~20 other PMods, but the last time I've checked it was working.

You have selected the example for ACL with ADXL345. This has different command set than the ACL2 with ADXL362 IC. Probably you wanted to say ACL2 and not ACL5.

Under the Custom tab select the ACL3/2 with ADXL362 and Run. These is a typo mistake, it should be ACL2 instead ACL3.
In case you use the Logic Analyzer, the Protocol tool won't be able to read data, so the uncheck this option otherwise you will get "Device ID mismatch".

image.png.3f4152b1d7ed5a0d7d6236bb4bf43c72.png

 

You can also use the Master tab

image.png.91aef23292f2d7acaf3533495f9737e5.png

Share this post


Link to post
Share on other sites
  • 0

Hi Attila 

Where do I get hold of Waveforms Beta 2 .

Is located here 

Or is there another download location ?

Best wishes 

Simon

Share this post


Link to post
Share on other sites
  • 0

Hi

This the latest beta version of waveforms i can find :  digilent.waveforms_beta_v3.13.1_64bit.exe  

You are using a not released for public use version of Waverforms maybe ??

Please can you send me an attachment with the python  file PMOD ACL3 ADXL362 IC and I will try that. 

Many thanks &best wishes

Simon

 

image.png.3d812932944660f7bd05da911f9dfe91.png

Share this post


Link to post
Share on other sites
  • 0

Hi Attila 

Still the same set up . Using the new way you suggest.

Still no working communications.  

Any more ideas of how to get this working  with the PMOD ACL2 which uses a ADXL362   IC running spi ??

I really would like to get this working . 

Best wishes

SImon

image.thumb.png.2841b2f9e4202002c5b8c72eca745c7e.png

Share this post


Link to post
Share on other sites
  • 0

Hi 

The PMOD MIC3 I have order should turn up soon . So I will try the example

https://blog.digilentinc.com/capturing-and-analyzing-live-audio/

https://testandmeasure.org/#/category/scripts/pmod-mic3-audio-streaming-recording-125baaaf

 

Maybe this will give some light on the issues causing the problems

Best wishes

Simon

Share this post


Link to post
Share on other sites
  • 0

Hi Attila

Just walked over to the goods in office and collected the PMOD MIC3 board  and tried the PMOD MIC3 with Digilent Analogue discover 2 . 

It just worked straight out of the box.

Download the script. Followed the read me document . Run the script.

Result -> Working PMOD MIC3 

So  my conclusion is there is some thing fishy with the PMOD ACL2 set up in the example script or the PMOD ACL2 board has some hidden secret.

Its time for your to do your Application Engineer magic and go get the bits from the cupboard and solve the case .

Look forward to hearing from you soon with a working PMOD ACL2 on your desk and some photos on this blog and copy of the working script on this blog page

Best wishes

Simon

 

Share this post


Link to post
Share on other sites
  • 0

Hi Attila 

As I need this working I am doing my own application engineering .

The script function inside the protocol.spi window does not seem to be working 

The script will not run and just gives the error message " Data transfer error "  which is not helpful . 

Outcome :: No usable result ... 

I had to fix a few things in script as the SPI  bus command where not correct. Indicating know one in Digilent has been testing the scripts properly. 

Digilent spi command     ::  Write(8, 0x0A, 0x00); // Read Register, Device ID 

Fixed SPI command                         Write(8, 0x0B, 0x00); // Read Register, Device ID

Best wishes 

Simon

//------------------------------------------------------------------------------------------------------

// This is the script I ran in the protocol.spi window:

// Pmod ACL3 - ADXL362

 

//************************************************************

// Script using Protocol UART.

// SPI BUS Set up

//************************************************************

//

// SPI Bus physical wired set up

//

// Select AD_2_DIO3 // SPI: /CS

// Clock AD_2_DIO4 // SPI: Clock

// DQ0 AD_2_DIO5 // SPI: MOSI

// DQ1 AD_2_DIO6 // SPI: MOS0

Select.value = 3; //Assigns pin Analog Disovery 2 GPIO Pin DIO 3

Select.Active.setValue(0);

Clock.value = 4; //Assigns pin Analog Disovery 2 GPIO Pin DIO 4

DQ0.value = 5; //Assigns pin Analog Disovery 2 GPIO Pin DIO 5

DQ1.value = 6; //Assigns pin Analog Disovery 2 GPIO Pin DIO 6

Clock.Frequency.value=5E3 ; // set spi clock freqncy at 5KHz

Clock.Polarity.value=0 ; // set up spi clock initial Polarity

Clock.Phase.value=0 ; // set up spi clock initial Phase

//************************************************************

 

 

Start();

Write(8, 0x0B, 0x00); // Read Register, Device ID

var rgID = Read(8, 4);

print(rgID);

Stop();

 

if(rgID[0] != 0xAD || rgID[1] != 0x1D || rgID[2] != 0xF2){

return "Device ID mismatch "+rgID;

}

else

{

Start();

Write(8, 0x0B, 0x0E); // Read Register, Data

var rg = Read(16, 4);

Stop();

// convert data bits to signed value relative to gravitational constant

// MSbit sign, LSBit 0.001g

var gx = 0.001* (rg[0]<<16) /256/256;

var gy = 0.001* (rg[1]<<16) /256/256;

var gz = 0.001* (rg[2]<<16) /256/256;

var temp = 0.065* (rg[3]<<16) /256/256;

return [gx,gy,gz,temp];

}

 

 

image.png

Share this post


Link to post
Share on other sites
  • 0

Hi Attilla

I wrote full proper script using the main script window.  As the protocol.spi custom window would not work as shown on the previous post.

This executed script below actually chatted to the PMOD ACL2 device but could not read the x,y,z,temp data for the  PMOD ACL3 only its chip ID .

Scripts run sequences is

1) Power up  AD2 internal PSU to power PMOD ACL3 card with 3V3

2) Set up the physical SPI bus 

3)  Send a SPI Write command to the PMOD ACL2 to issue it a reset command

4)  Read the CHIP ID for ADXSL362 using SPI BUS

5) Read the status register 

6)  Set the Power control register to 0x22

7)  Read the status register 

8 )  Read ADXL362  using 8 bit  values  X{H} Y{H} Z{H}

9)  Read ADXL362  using 16  bit  values  X{L,H} Y{L,H} Z{L,H} Temp{L,H} as 16 bit numbers

10)  Power down AD2 internal PSU to power PMOD ACL3 card  .

 

Please help to get this to work fully . This is after all what application engineers do ...  

Attached is a copy of my waveforms work book. So you can actually take it and get to work with the pieces from your office cupboard.

Best wishes 

Simon

//###################################################################################################### 

// This is the output of the script 

  /*

    SPI Script for PMOD ACL2 3 axis accelometer with Analog devices ADXL362 running

     Device is ADXL362 : SPI register 0x00 read { 0dxx in decimal} : 173,29,242,2

     ADXL362 Status regiser raw data after reset = 173

     Write SPI [0x0A, 0x2D , 0x22 ] :: ADXSL262 SPI register setup for POWER_CTL to be permantly on without sleep

     ADXL362 Status regiser raw data after POWER_CTL_setup = 0

     Raw data {8 bit data} {x,y,z} = 0,0,192

     Write/Read SPI [0x0B, 0x0E] :: Read ADXL362 Device X{L,H} Y{L,H} Z{L,H} Temp{L,H} as 16 bit numbers Page 23 of the ADXL362 Data sheet

*/

//######################################################################################################

//************************************************************

//

// Real script to chat with PMOD ACL2 3 axis accelometer

// using a Digilent Analogue Discovery 2

//

// ref for spi register data : https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL362.pdf

//

// ref https://os.mbed.com/users/tkreyche/notebook/adxl362_tkreyche/ look at the bottom of the page there is a NXP ARM C mbed example

//

// Note for this script to work the following Waveforms window panels have to be open

// - Supplies - the internal AD2 PSU can be used

// - script -- location where this script is cut and pasted

// - Protocol - required to have acces to the AD2 internal SPI bus engine

//

//************************************************************

clear(); // clear display screen

 

print(" SPI Script for PMOD ACL2 3 axis accelometer with Analog devices ADXL362 running " + "\n\r ");

 

//************************************************************

// Set up mini PSU inside Analogue Discovery 2 to supply 3.3V

//************************************************************

 

Supplies.Output.PositiveSupply.Voltage.value=3.3;

Supplies.Output.PositiveSupply.Enable.setEnable();

Supplies.Output.NegativeSupply.Enable.setDisable();

Supplies.run(); // Turn on PSU unit inside AD2

wait(2); // wait 1 seocnds for system to stabilise.

 

//************************************************************

// Script using Protocol UART.

// SPI BUS Set up

//************************************************************

//

// SPI Bus physical wired set up

//

// PMOD PIN 1 =  : Select AD_2_DIO3 // SPI: /CS

// PMOD PIN 4  = Clock AD_2_DIO4 // SPI: Clock

// PMOD PIN 2  =    DQ0 AD_2_DIO5 // SPI: MOSI

// PMOD PIN 3  =   DQ1 AD_2_DIO6 // SPI: MOS0

//  PMOD PIN 5  = GND=  AD2_GND

//  PMOD PIN 6  =  VCC =  AD2_VPOS_VCC

// 

 

 

Protocol.SPI.Select.value = 3; //Assigns pin Analog Disovery 2 GPIO Pin DIO 3

Protocol.SPI.Select.Active.setValue(0);

Protocol.SPI.Clock.value = 4; //Assigns pin Analog Disovery 2 GPIO Pin DIO 4

Protocol.SPI.DQ0.value = 5; //Assigns pin Analog Disovery 2 GPIO Pin DIO 5

Protocol.SPI.DQ1.value = 6; //Assigns pin Analog Disovery 2 GPIO Pin DIO 6

Protocol.SPI.Clock.Frequency.value=1E6 ; // set spi clock freqncy at 1MHz page 19 of the data sheet min spi clock 1MHz

Protocol.SPI.Clock.Polarity.value=0 ; // set up spi clock initial Polarity

Protocol.SPI.Clock.Phase.value=0 ; // set up spi clock initial Phase

//************************************************************

 

 

 

 

 

//************************************************************

// Main program block read ADXL362 Device ID

//************************************************************

 

 

if(!('Protocol' in this)) throw "Please open the Protocol tool";

 

Protocol.Mode.text = "SPI"; // make sure SPI tab is selected

Protocol.SPI.Start(); // SPI activate select

 

Protocol.SPI.Write(8, [0x0A, 0X1F, 0x52]); // SPI RESET ADXL362 by making a soft reset page 26 of the ADXL362 Data sheet : SOFT RESET REGESTER

 

wait(0.100); // wait 100 milli second before reading ID data . Datahseet say device needs 500 micro seconds to stabilise after reset.

 

Protocol.SPI.Write(8, [0x0B, 0x00]); // Read ADXL362 Device ID Page 23 of the ADXL362 Data sheet

var rgID = Protocol.SPI.Read(8, 4); // read 4 words of 16 bit length

Protocol.SPI.Stop(); // deactivate select

var Device_ok=0;

if(rgID[0] != 0xAD || rgID[1] != 0x1D || rgID[2] != 0xF2){

print(" Device ID mismatch " + rgID );

print(" ");

print(" Is the physical SPI Bus physical wired set up correctly ?? " );

print(" ");

print(" The SPI setup should be :- ");

print(" ");

print(" Select AD_2_DIO3 // SPI: /CS ");

print(" Clock AD_2_DIO4 // SPI: Clock ");

print(" DQ0 AD_2_DIO5 // SPI: MOSI ");

print(" DQ1 AD_2_DIO6 // SPI: MOS0 ");

 

}

else

{

print(" Device is ADXL362 : SPI register 0x00 read { 0dxx in decimal} : " + rgID + "\n\r" );

Device_ok=1;

}

 

//**********************************************************************************

//

// Result shoudl be : Read: hAD, h1D, hF2, h02,

// Output : 173,29,242,2 in dec --> hex --> 0xAD 0x1D 0xF2 Ox02

//

//*********************************************************************************

 

function bitExtracted( number, k, p)

{

// Function to extract k bits from p position

// and returns the extracted value as integer

// eg first 11 bits of a 16 bit number

 

// bitExtracted(int 0xfff,10,0)

 

return (((1 << k) - 1) & (number >> (p - 1)));

}

 

 

function initial_first_measuremnt_test()

{

Protocol.SPI.Start(); // activate select

 

/*

*

* ADXSL262 SPI register setup for POWER_CTL to be permantly on without sleep

*

* Bit 7 Reserved 0x0

* Bit 6 External CLK =1 int=0 0x0

* Bit 5:4 Power ns Noise Trade off 0x10 = Ultra Low Noise

* Bit 3 Wakeup mode 0x0 = OFF

* Bit 2 Autosleep 0x0 = OFF

* BIT 1:0 Measurement state 0x10 = Measurment Mode

*

* Resultant setting = b00 10 00 10 = 0x22

*/

 

Protocol.SPI.Write(8, [0x0B, 0x00]); // Read ADXL362 STATUS_reg Page 23 & 25 of the ADXL362 Data sheet

var STATUS_reg = Protocol.SPI.Read(8, 1); // read 4 words of 16 bit length

print(" ADXL362 Status regiser raw data after reset = " + STATUS_reg + "\n\r" );

wait(0.01); // wait 10 milli second before reading data.

 

 

Protocol.SPI.Write(8, [0x0A, 0x2D , 0x22 ]); // ADXSL262 SPI register setup for POWER_CTL to be permantly on without sleep

print(" Write SPI [0x0A, 0x2D , 0x22 ] :: ADXSL262 SPI register setup for POWER_CTL to be permantly on without sleep " + "\n\r" );

wait(0.01); // wait 10 milli second before reading data.

 

Protocol.SPI.Write(8, [0x0B, 0x00]); // Read ADXL362 STATUS_reg Page 23 & 25 of the ADXL362 Data sheet

var STATUS_reg = Protocol.SPI.Read(8, 1); // read 4 words of 16 bit length

print(" ADXL362 Status regiser raw data after POWER_CTL_setup = " + STATUS_reg + "\n\r" );

wait(0.01); // wait 10 milli second before reading data.

 

 

 

 

 

 

 

Protocol.SPI.Write(8, [0x0B, 0x08]); // Read ADXL362 Device X{H} Y{H} Z{H} Page 23 of the ADXL362 Data sheet

var rg_eight_bit = Protocol.SPI.Read(8, 3); // read 4 words of 16 bit length

print(" Raw data {8 bit data} {x,y,z} = " + rg_eight_bit + "\n\r" );

wait(0.01); // wait 10 milli second before reading data.

 

 

 

Protocol.SPI.Write(8, [0x0B, 0x0E]); // Read ADXL362 Device X{L,H} Y{L,H} Z{L,H} Temp{L,H} Page 23 of the ADXL362 Data sheet

var rg = Protocol.SPI.Read(16, 4); // read 4 words of 16 bit length

wait(0.01); // wait 10 milli second before reading data.

 

print(" Write/Read SPI [0x0B, 0x0E] :: Read ADXL362 Device X{L,H} Y{L,H} Z{L,H} Temp{L,H} as 16 bit numbers Page 23 of the ADXL362 Data sheet " + "\n\r" );

Protocol.SPI.Stop(); // deactivate select

var gx = 0.001* (rg[0]<<16) /256/256;

var gy = 0.001* (rg[1]<<16) /256/256;

var gz = 0.001* (rg[2]<<16) /256/256;

//var temp = 0.065* (rg[3]<<16) /256/256;

 

var temp_sign= bitExtracted(rg[3],10,1);

var temp =bitExtracted(rg[3],1,11);

if(temp_sign==1){ temp= temp * -1 ; }

 

print(" Raw data {16 bit data} {x,y,z,temp} = " + rg + "\n\r" );

print(" Accelerometer initial X value = " + gx );

print(" Accelerometer initial y value = " + gy);

print(" Accelerometer initial z value = " + gz);

print(" Accelerometer initial temp value = " + temp);

}

if ( Device_ok==1)

{

initial_first_measuremnt_test();

}

 

//************************************************************

// Power down mini PSU inside Analogue Discovery 2 to supply 3.3V

//************************************************************

 

Supplies.stop(); // Turn off PSU unit inside AD2 after measurment has finished.

 

 

//************************************************************

 

SPI_test_2.dwf3work

Share this post


Link to post
Share on other sites
  • 0

Hi Attila

I am being hope fully here.

Please put some effort in here,  If you are to busy to fix the case ,  please get the case referred to someone else in your team who can spend the time to get to work.

It would be really interesting to be able to display 3 way axis accelerometer data as 3 reference scope channels just like the PMOD MIC3 example  reference  this post notes

If you can get this application working it would make a very good application for university teaching for example with robots to get student use to  the Analog disocvery 2.

So the student can execute robot to move using a command line call . so some thing like 

  var move_robot = Tool.exec("robot_move.exe", [ " 5cm left , 5 cm up "])

  SPI read PMOD ACL3 on a 100ms time step  so as to get acceleration date during the move of the robot arm.

There are lots of thing this stuff can be used for anyway so it is good idea to get it working.

AD2 is very good tool with many options !!

 

 

Share this post


Link to post
Share on other sites
  • 0

Hi @sib

Thank you for sharing your code. I will test the example and your code as soon I find the ACL2, or get a new one...

You may need a Protocol.SPI.Stop/Start() between "SPI RESET" and "Read Device ID".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now