Jump to content

SIB-V2

Members
  • Posts

    10
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

SIB-V2's Achievements

Member

Member (2/4)

2

Reputation

  1. Hi Attila , Any thoughts on my request ... If not you then can you put me in contact with one of your colleagues who would be the correct person to chat too. When your colleagues are back in the office in the USA from covid work at home I will call them to find some one to help me .. I would prefer i am pointed at the correct person rather than calling around to find the correct person. Fully the case can be solved.. Best wishes SIB
  2. Hi Attila , Is there any chance we can work together to get the SPI part of the driver fixed . Then all there will be a javascript driver for all the embedded protocols SPI , I2C and UART together with power control. What are your thoughts ?? Best wishes & friendly greetings SIB
  3. Hi Attila This fixed the case now the I2C part of the library works. Below are the updated and working drivers. Best wishes & friendly greetings SIB Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.dwf3work Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.js Digilent_AD2_Script_master.js
  4. Dear Attila Please find enclosed the following . This took more than 4 hours to prepare all the documentation please treat as such. I am using the latest version of Digilent Waveforms and the latest Waveforms SDK. - Master Javascript driver for Digilent Analogue Discover AD2 which can be used inside Waveforms - SPI Setup , read & write & Initialise (1) . Status NOT Working . Needs Digilent Help to fix (%%) - I2C Setup , read & write & Initialise (2) . Status NOT Working . Needs Digilent Help to fix - UART Setup , read & write & Initialise(3) . ** - GPIO Setup, Set individual GPIO Pin Output States (4) Working - PSU Control, Set PSU voltage , turn on and off (5) Working - Python driver directly to control ON-SEMI CAT9532 using Digilent Analogue Discover AD2 & Digilent Waveforms ## Enclosed are all the attached scripts . ** Mostly likely works as driver details taken from working examples . See driver for while for web links reference. (%%) See previous efforts here to get it working    https://forum.digilentinc.com/topic/21997-waveforms-with-accelerometer-digilent-analog-discovery-2-with-pmod-acl2-java-script-spi/#comment-63633 https://forum.digilentinc.com/topic/19237-waveforms-with-accelerometer/page/2/#comment-52495 I am trying to get the I2C driver function of the AD2 to work to drive a ON-SEMI CAT9532 LED driver. Set up , I have two Digilent Analogue Discover AD2 - Device 1 : Digilent AD2 (Device A) I2C driver source . A) Device is programed using Digilent Waveforms Javascript B) Direct control though Digilent Waveforms I2C Master interface C) Direct control though Digilent Waveforms I2C Master script interface D) Direct control Waveforms SDK & Python - Device 2 : Dilenet AD2 (Device B) as I2C spy device - Device 3 : TotalPhase Advark I2C/SPI professional I2C development tool Direct control & Programming by XML program script. https://www.totalphase.com/products/aardvark-i2cspi/ I own (2) two Analogue Discovery devices. What worked Device 2 : It could work perfectly as a I2C spy mode device Device 3: Worked perfectly straight out of the box using the GUI interface. Took 20 mins to have working solution. This is professional I2C product that has been in the market for 10 years plus. What failed Device 1: Did not output the correct I2C packet no mater how it was programmed. Device 1 : Had 10K pull up resistor attached to the VCC 3V3 rail on the I2C: SDA & I2C:SCL & I2C:/RESET. Conclusion There seems to be general issue with the AD2 and getting it to work as driver for I2C and SPI . Which is a long term issue. I have spent a long time searching for all the small details to build up the driver set so that should work with Digilent Analogue Discover AD2 & Digilent Waveforms but if the hardware of the AD2 is not co-operative or the staff in Digilent not being supportive there is only so much I can do . Requested Help 1. Fix the Waveforms AD2 Javascript and Python Waveforms SDK so it works for SPI & I2C . There is something missing here, where it would be good to fix to improved your AD2 products for the whole community of AD2 users 2. Have a Digilent published AD2 drivers that work for SPI & I2C & UART & GPIO & PSU control for waveforms and waveforms SDK. So Attila the case is in your lap now .. Please put some effort in to fix it or show me how to fix it . I have the feeling your quite a skilled person. The result should be posted here as a product example : https://projects.digilentinc.com/products/waveforms?sort=updated Background I am a electronic engineer with 20+ years development experience , I have have successfully used Digilent AD2 to design 3 products end to end and have been using it for quite a few years. I can program in Python , Microsoft VB.net and Javascript. I have personally purchased two pieces of AD2 out of my own money as feel they are such a good tool. I am committed to using the AD2 as I can see and experience that it is a super swiss army knife for use in a development of embedded electronics. I have also purchased a full profesional copy of National instruments Labview for use with AD2 but , have suspended learning to use labview until this I2C & SPI issue is resolved with the AD2 Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.py Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.js Digilent_AD2_Script_I2C_control_of_on-semi_CAT9532.dwf3work Digilent_AD2_Script_master.js
  5. Hi Brando 1 ) Install the Digilent waveforms SDK . https://blog.digilentinc.com/waveforms-sdk-is-now-updated-to-include-python-3/ 2) Visit on your PC C:\Program Files (x86)\Digilent\WaveFormsSDK\samples\py Here are a whole lot of python examples to control and use I2C & SPI with Analog Discovery AD2 . I use Active Python , which I find gives the best results as most of the python components are actually fully tested and work. 3) If you have success or failure . post up a message on the forum showing your results. Best wishes & Friendly greetings SIB. PS , I am AD2 user and not employee of Digilent.
  6. Hi Attila Have you have had almost 2 years to paste up a working example of how to get a PMOD ACL2 working but I still can not finding a working example any where. This is the latest code for from the last time Is there any chance you will actually spend the time to get this to work .. I feel it is not so good that a good tool like AD2 is being not supported. Best wishes & friendly greetings SIB Direct_protocol_test.dwf3work SPI_test.dwf3work SPI_test_2.dwf3work SPI_test_3.dwf3work SPI_test_4.dwf3work SPI_test_5_test.dwf3work
  7. // This posted here so that Google and Bing search the script to help other users of Digilent Analog Discovery AD2 // and Digilent wave forms find programming examples which are very difficult to find. // This driver is work in progress . SPI & I2C functionality not working yet . // for use with Digilent Analog Discovery AD2 script engine. // // Attila : Please leave this post up on the forum as I spent a very long time curating the script to find all the // small example pieces of code . // // ------------------------------------------------------------------------------------------------------------------- //************************************************************ // // Notes on the basic script syntax can be found here // // You can use the links in the Help, other educational pages or google... // // https://doc.qt.io/qt-5/ecmascript.html // // https://www.w3schools.com/jsref/jsref_obj_array.asp // // Note for this script to work the following Waveforms window panels have to be open // - Supplies - the internal AD2 PSU can be used // - Main script -- location where this script is cut and pasted // - Protocol ** - required to have acces to the AD2 internal SPI or UART or I2C bus engines // // edit using Notepad++ with the langauge Javascript selected. // // //************************************************************ //************************************************************ //Function blocks //************************************************************ 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 spi_initialise() { if(!('Protocol' in this)) throw "Please open the Protocol tool window"; //************************************************************ // Script using Protocol SPI. // 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 // // !! Remember to change the set up in function spi_pin_io_setup() if the SPI Pins are re assigned on the AD2 DIO GPIO pins !! Protocol.Mode.text = "SPI"; // make sure SPI tab is selected Protocol.SPI.Select.Active.value=0; Protocol.SPI.Clock.Polarity.value=0 ; // set up spi clock initial Polarity Protocol.SPI.Clock.Phase.value=0 ; // set up spi clock initial Phase Protocol.SPI.Clock.Frequency.value=1e6 ; // set spi clock freqncy at 1MHz page 19 of the data sheet min spi clock 1MHz if(Protocol.SPI.Clock.Frequency.value > 1e6) Protocol.SPI.Clock.Frequency.value = 1e6; Protocol.SPI.Select.value = 3; //Assigns pin Analog Disovery 2 GPIO Pin DIO 3 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 // // SPI: MOSI Protocol.SPI.DQ1.value = 6; //Assigns pin Analog Disovery 2 GPIO Pin DIO 6 // SPI: MOS0 Protocol.config() // apply configuration changes now print(" SPI initialised " + "\n\r" ); print(" SPI Select is connect to AD2 DIO Port : " + Protocol.SPI.Select.value + "\n\r" ) ; print(" SPI Clock connect to AD2 DIO Port : " + Protocol.SPI.Clock.value + "\n\r" ) ; print(" SPU MOSI port connect to AD2 DIO Port : " + Protocol.SPI.DQ0.value + "\n\r" ) ; print(" SPU MOSO port connect to AD2 DIO Port : " + Protocol.SPI.DQ1.value + "\n\r" ) ; print("\n\r"+" SPI initialisation complete " + "\n\r" ) ; //************************************************************ // notes // ===== // // 1. On the AD and AD2 the digital IO pins use LVCMOS 3V3 standard. These are supplied at 3.3V and have 200 Ohm PTC and clamping diodes to GND and to 3.3V for protection. // It will drive the digital wires at 3.3V and connecting 5V signals directly, without series resistor, it will sink about 10mA through the PTC and 3v3 diode. // As for noise, make sure to have ground connection between the two devices. // // 2. The WF/Protocol/UART uses the Stop length option only for transmission, this is not relevant for reception. // // 3. The UART TX filed lets you type in characters, hexadecimal values are not supported here. // Special chars you can copy/paste from other place or send from file. //************************************************************ } function i2c_initialise() { if(!('Protocol' in this)) throw "Please open the Protocol tool window"; //************************************************************ // Script using Protocol I2C. // i2C BUS Set up //************************************************************ // // I2C Bus physical wired set up // // I2C SDA AD_2_DIO0 // I2C SCL AD_2_DIO1 // /Reset AD_2_DIO3 // // // // // Note Only DIO pins 0 through to 9 can be used for Protocol functions { SPI , I2C or UART} // // var I2C_reset_AD2_DIO_port = 3 ; // Set to AD2 DIO Port which controls I2C /Reset io line Protocol.Mode.text = "I2C"; // make sure SPI tab is selected Protocol.I2C.Mode.value = 1; //Set the I2C Protocol tool into Master Mode Protocol.I2C.SCL.value = 1; //Set the SCL pin to be DIO 0 Protocol.I2C.SDA.value = 0; //Set the SDA pin to be DIO 1 Protocol.I2C.SCL.Frequency.value = 100000; //Set the SCL clock frequency to 100 kHz //Protocol.I2C.Clockstretching.value = 1; //Enable Clock Stretching´.. This line is not functioning Protocol.I2C.ClockStretching.enable; // This is the replacement lines Protocol.config() // apply configuration changes now // flip the GPIO active low reset line set low then set high set_static_io_pin(I2C_reset_AD2_DIO_port,0); wait(0.1); // wait 100 milli second before next instruction. set_static_io_pin(I2C_reset_AD2_DIO_port,1); wait(0.1); // wait 100 milli second before next instruction. // ref https://forum.digilentinc.com/topic/4942-i2c-subaddress-not-working-properly-in-the-script-tool/ // Ref https://forum.digilentinc.com/topic/21906-how-to-measure-scope-and-protocol/ // ref https://forum.digilentinc.com/topic/18944-reading-i2c-via-script-displays-wrong-data/ print(" I2C initialised " + "\n\r" ); print(" I2C SCL connect to AD2 DIO Port " + Protocol.I2C.SCL.value + "\n\r" ) ; print(" I2C SDA connect to AD2 DIO Port " + Protocol.I2C.SDA.value + "\n\r" ) ; print(" I2C /RESET port connect to AD2 DIO Port " + I2C_reset_AD2_DIO_port + "\n\r" ) ; print("\n\r"+" I2C initialisation complete " + "\n\r" ) ; //************************************************************ // notes // ===== // // 1. On the AD and AD2 the digital IO pins use LVCMOS 3V3 standard. These are supplied at 3.3V and have 200 Ohm PTC and clamping diodes to GND and to 3.3V for protection. // It will drive the digital wires at 3.3V and connecting 5V signals directly, without series resistor, it will sink about 10mA through the PTC and 3v3 diode. // As for noise, make sure to have ground connection between the two devices. // // 2. The WF/Protocol/UART uses the Stop length option only for transmission, this is not relevant for reception. // // 3. The UART TX filed lets you type in characters, hexadecimal values are not supported here. // Special chars you can copy/paste from other place or send from file. //************************************************************ } function i2c_notes_read_with_i2c_sub_address() { // // Ref https://forum.digilentinc.com/topic/4942-i2c-subaddress-not-working-properly-in-the-script-tool/ // // // Special sub-addressing is only required for read operations. In this process the sub-address write is followed by a restart and read. // ref https://www.i2c-bus.org/repeated-start-condition/ // For write operations you can just concatenate the "sub-address" with the array of data you have to write. var a = [1,2] // sub-address var b = [3,4] // data var c = a.concat(b) Protocol.I2C.Write(0x48, c) } function i2c_write( address , data_array_to_write) { // // Examples of i2c_write // // address = 0x60 // data_array_to_write = [0,1] // Protocol.I2C.Write(address, data_array_to_write ) ; // notes // ===== // // 1. On the AD and AD2 the digital IO pins use LVCMOS 3V3 standard. These are supplied at 3.3V and have 200 Ohm PTC and clamping diodes to GND and to 3.3V for protection. // It will drive the digital wires at 3.3V and connecting 5V signals directly, without series resistor, it will sink about 10mA through the PTC and 3v3 diode. // As for noise, make sure to have ground connection between the two devices. // // 2. The WF/Protocol/UART uses the Stop length option only for transmission, this is not relevant for reception. // // 3. The UART TX filed lets you type in characters, hexadecimal values are not supported here. // Special chars you can copy/paste from other place or send from file. } function i2c_read( address , number_of_bytes_to_read_back ) { // // Examples of i2c_read // // address = 0x60 // number_of_bytes_to_read_back =32 // var bytes = Protocol.I2C.Read( address, number_of_bytes_to_read_back) ;// returns array of x bytes read from device address 0x0D return bytes ; } function i2c_read_example() { // From the Script tool you can perform I2C transfer like this: var bytes = Protocol.I2C.Read(0x0D, 2) ;// returns array of 2 bytes read from device address 0x0D var temp = (((bytes[0]<<26) | (bytes[1]<<18)) >>18)/32; print("Temp: "+temp+"*C") // ref https://forum.digilentinc.com/topic/17333-digital-discovery-logic-dios-are-different-to-dios-from-the-patterngenerator/ } function spi_pin_io_setup() { 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 "); } function UART_initialise() { clear(); // clear Output log // // Note Only DIO pins 0 through to 9 can be used for Protocol functions { SPI , I2C or UART} // // if(!('Protocol' in this)) throw "Please open the Protocol instrument"; Protocol.Mode.text = "UART"; // make sure UART tab is selected Protocol.UART.TX.value = 0; // Set up UART TX pin on Digilent AD2 :: DIO_0 Pin Protocol.UART.RX.value = 1; // Set up UART RX pin on Digilent AD2 :: DIO_1 Pin Protocol.UART.Bits.value=8; // Sets or gets the UART number of bits. Protocol.UART.Parity.text="None" ;// Sets or gets the parity setting: “None”, “Even”, “Odd”, “Mark (High)”, “Space (Low)”. Protocol.UART.Rate.value=9600; // Sets or gets the baud rate setting Protocol.config(); // apply configuration changes now Protocol.UART.Receiver(); // reset receiver - that is too start receiving data print(" UART Serial Bus initialised . Beware this is 3V3 Logic RS232 & Not True +/- 15V Rs232" + "\n\r" ); print(" I2C SCL connect to AD2 DIO Port " + Protocol.I2C.SCL.value + "\n\r" ) ; print(" I2C SDA connect to AD2 DIO Port " + Protocol.I2C.SCL.value + "\n\r" ) ; print("\n\r"+" I2C initialisation complete " + "\n\r" ) ; // // ref https://forum.digilentinc.com/topic/21308-ad2-protocol-uart-script-reading-vaillant-ebus/ // // https://forum.digilentinc.com/topic/21353-use-of-multiple-protocol-uart-ports-via-script-possible-at-different-times/ // // notes // ===== // // 1. On the AD and AD2 the digital IO pins use LVCMOS 3V3 standard. These are supplied at 3.3V and have 200 Ohm PTC and clamping diodes to GND and to 3.3V for protection. // It will drive the digital wires at 3.3V and connecting 5V signals directly, without series resistor, it will sink about 10mA through the PTC and 3v3 diode. // As for noise, make sure to have ground connection between the two devices. // // 2. The WF/Protocol/UART uses the Stop length option only for transmission, this is not relevant for reception. // // 3. The UART TX filed lets you type in characters, hexadecimal values are not supported here. // Special chars you can copy/paste from other place or send from file. } function UART_Test() { UART_initialise(); Protocol.UART.Receiver(); // start receiver wait(); Protocol.UART.Send("hello"); // TX wait(0.1); // 100ms wait for RX, depends on the external device and rate print(Protocol.UART.Receive()); // RX } function UART_Test_example_2() { UART_initialise(); Protocol.UART.Receiver(); // reset receiver - that is start receiving data var rx = []; while(wait(1)) { // wait 1 sec and repeat while not stopped rx = rx.concat(Protocol.UART.ReceiveArray()); // append new words while(rx.length>10) { if(rx.shift()==0xAA) continue; if (rx[1] == 0xB5 && rx[2]== 0x11 && rx[7] == 0x09) { // find the temperatures for displaying print ("Temp 1: " + (rx[8]/2).toFixed(1) + " °C Temp 2: " + (rx[9]/2).toFixed(1) + " °C"); // decimal data devided by 2 bring °Celsius } } } } function UART_Test_example_3() { UART_initialise(); Protocol.UART.Receiver(); // reset receiver - that is start receiving data // Protocol.UART.Send("Hello") ; // send text with ending var rx = Protocol.UART.Receive(); // receive text print(rx) ; // Protocol.UART.Send("Hello ", false); // send text custom ending var rx = Protocol.UART.Receive(); // receive text print(escape(rx)); // Protocol.UART.SendArray([1,2,3,4,5,0], false); // send array custom ending var rx = Protocol.UART.ReceiveArray(); // receive array print(rx); } function spi_write( address , data_to_write) { Protocol.SPI.Start(); Protocol.SPI.Write( address ,data_to_write ); // Read Register, Device ID Protocol.SPI.Stop(); wait(0.1); // wait 100 milli second before next instruction. } function spi_write_read( address , data_to_write, number_of_bytes_to_read_back) { Protocol.SPI.Start(); Protocol.SPI.Write( address ,data_to_write ); // Read Register, Device ID wait(0.1); // wait 100 milli second before reading data. var rg_data = Protocol.SPI.Read(address, number_of_bytes_to_read_back); Protocol.SPI.Stop(); wait(0.1); // wait 100 milli second before next instruction. return rg_data ; } function static_io_example() { // ref https://forum.digilentinc.com/topic/21512-how-to-energize-multiople-staticio-given-only-when-a-certain-dio-is-on/ // ref https://forum.digilentinc.com/topic/2150-staticio-scripting-documentations-for-waveforms3/ // ref https://forum.digilentinc.com/topic/18737-export-issues/ // ref https://forum.digilentinc.com/topic/18789-some-functional-problems/ clear() if(!('StaticIO' in this)) throw "Please open the StaticIO instrument"; const IO = 7; const delay = 0.3; print("Running StaticIO script"); for(var c = 0; c <= IO; c++) { StaticIO.Channel0.DIO[c].Mode.text = "Switch"; } StaticIO.run() while(wait()){ // while script not stopped if(StaticIO.Channel1.DIO8.Input.value == 1) { for(var c = 0; c <= IO; c++) { StaticIO.Channel0.DIO[c].text = "1"; StaticIO.config(); // apply changes now if(!wait(delay)) return; // exit on script stop StaticIO.Channel0.DIO[c].text = "0"; StaticIO.config(); if(!wait(delay)) return; } for(var c = IO; c > 0; c--) { StaticIO.Channel0.DIO[c-1].text = "1"; StaticIO.config(); if(!wait(delay)) return; StaticIO.Channel0.DIO[c-1].text = "0"; StaticIO.config(); if(!wait(delay)) return; } } } } function static_io_example_2() { // ref https://forum.digilentinc.com/topic/21512-how-to-energize-multiople-staticio-given-only-when-a-certain-dio-is-on/ // ref https://forum.digilentinc.com/topic/2150-staticio-scripting-documentations-for-waveforms3/ // ref https://forum.digilentinc.com/topic/18737-export-issues/ // ref https://forum.digilentinc.com/topic/18789-some-functional-problems/ clear(); if(!('StaticIO' in this)) throw "Please open the StaticIO instrument"; // 1.Probe print("Running pin 1, channel 1") StaticIO.Channel0.DIO[3].text = "0"; StaticIO.Channel0.DIO[4].text = "1"; StaticIO.Channel0.DIO[5].text = "1"; StaticIO.Channel0.DIO[0].text = "0"; StaticIO.Channel0.DIO[1].text = "0"; StaticIO.Channel0.DIO[2].text = "0"; StaticIO.config(); // force immediate configuration wait(1); // wait on external device/circuit } function static_io_example_3() { // // This is what's available on the wiki: // // .StaticIO // // .Channel#: groups of 8 signals // .Mode.text: select between: I/Os, Slider, Progress // .Input.value: input value // .DIO#: I/Os // .Input.checked: input value // .Mode.text: select between: LED, Button, Switch // .Button.text: select between: 0/1, 1/0, Z/1, 1/Z, Z/0, 0/Z // .Switch.text: select between: TS, PP, OS, OD // ref https://forum.digilentinc.com/topic/2150-staticio-scripting-documentations-for-waveforms3/ // I got the DIO13 configured as a PushPull Switch, but how do you set the actual value that you want the pin to output? // Configure Static IO StaticIO.Channel1.Mode.text = "I/Os" // Configure Red LED StaticIO.Channel1.DIO13.Mode.text = "Switch" StaticIO.Channel1.DIO13.Switch.text= "PP" } function set_static_io_pin( AD2_Dio_pin , boolean_state ) { if(!('StaticIO' in this)) throw "Please open the StaticIO instrument"; if( boolean_state == 1) { StaticIO.Channel0.DIO[AD2_Dio_pin].text = "1"; StaticIO.config() // force immediate configuration } if( boolean_state == 0) { StaticIO.Channel0.DIO[AD2_Dio_pin].text = "0"; StaticIO.config() // force immediate configuration } } function power_up_psu( Power_supply_voltage ) { //************************************************************ // Set up mini PSU inside Analogue Discovery 2 to supply 3.3V //************************************************************ if(!('Supplies' in this)) throw "Please open the Supplies tool window"; Supplies.Output.PositiveSupply.Voltage.value=Power_supply_voltage; Supplies.Output.PositiveSupply.Enable.setEnable(); Supplies.Output.NegativeSupply.Enable.setDisable(); Supplies.run(); // Turn on PSU unit inside AD2 print(" Power supply is UP VCC = " + Power_supply_voltage + "\n\r" ); wait(5); // wait 1 seocnds for system to stabilise. //*********************************************************** } function power_down_psu() { //************************************************************ // Power down mini PSU inside Analogue Discovery 2 to supply 3.3V //************************************************************ print(" PSU is powering down" ); Supplies.stop(); wait(5); // wait 5 second before reading data. Supplies.Output.PositiveSupply.Voltage.value=0.3; Supplies.Output.PositiveSupply.Enable.setEnable(); Supplies.Output.NegativeSupply.Enable.setDisable(); Supplies.run(); // Turn on PSU unit inside AD2 wait(10); // wait 10 second before reading data. Supplies.stop(); // Turn off PSU unit inside AD2 after measurment has finished. print(" PSU is powered down" ); //*********************************************************** } function PMOD_ADXL362_not_working() { //************************************************************ // Example block read ADXL362 Device ID : Start //************************************************************ clear(); // clear display screen print(" SPI Script for PMOD ACL2 3 axis accelometer with Analog devices ADXL362 running " + "\n\r "); power_up_psu( 3.3 ) ; // Power up PSU to VCC = 3v3 spi_initialise(); // set up spi bus var STATUS_reg =spi_write_read( 8, [0x0B, 0x00], 1) ; // Read ADXL362 STATUS_reg Page 23 & 25 of the ADXL362 Data sheet & read 1 words of 8 bit length print(" ADXL362 Status regiser raw data after reset = " + STATUS_reg + "\n\r" ); wait(0.01); // wait 10 milli second before reading data. var rgID = spi_write_read( 8, [0x0B, 0x00], 4) ; var Device_ok=0; if(rgID[0] != 0xAD || rgID[1] != 0x1D || rgID[2] != 0xF2){ print(" Device ID mismatch rgid(0) " + rgID[0] ); print(" Device ID mismatch rgid(1) " + rgID[1] ); print(" Device ID mismatch rgid(2) " + rgID[2] ); print(" "); print(" Is the physical SPI Bus physical wired set up correctly ?? " ); print(" "); spi_pin_io_setup(); } 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 // //********************************************************************************* if ( Device_ok==1) { /*--------------------------------------------------------------------------------------------------------------- * * 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 *---------------------------------------------------------------------------------------------------------------*/ spi_write( 8,[0x0A, 0x2D, 0x02] ); // Power Control Register, Measurement Mode var rg = spi_write_read( 8, [0x0B, 0x0E], 8) ; // convert data bits to signed value relative to gravitational constant // MSbit sign, LSBit 0.001g for default 2g mode var gx = (0.001* ((rg[1]<<28) | (rg[0]<<20)) /1048576).toFixed(3); var gy = (0.001* ((rg[3]<<28) | (rg[2]<<20)) /1048576).toFixed(3); var gz = (0.001* ((rg[5]<<28) | (rg[4]<<20)) /1048576).toFixed(3); var tp = (0.065* ((rg[7]<<28) | (rg[6]<<20)) /1048576).toFixed(2); 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 = " + tp); } } //************************************************************ // Main program block : Start //************************************************************ clear(); // clear display screen print(" Script Main body start " + "\n\r "); power_up_psu( 3.3 ) ; // Power up PSU to VCC = 3v3 // ********************** // User code start // ********************** // ********************** // User code stop // ********************** power_down_psu(); //************************************************************ //************************************************************ // Main program block : Stop End //************************************************************ Digilent_AD2_Script_master.js
  8. See https://forum.digilentinc.com/topic/21997-waveforms-with-accelerometer-digilent-analog-discovery-2-with-pmod-acl2-java-script-spi/#comment-63633 Question has moved here
×
×
  • Create New...