Jump to content
  • 0

DD: How to add latch pulse to SPI


Stefan-F

Question

 

Hello,

to load data into a serial DAC, a separate latch pulse is needed at the end of an SPI transfer.

I tried to achieve this using a Custom SPI protocol and adding control for an extra output pin.

According to help file:

Quote

The Custom mode lets you write communication script with the following functions:

<snip>
* DIO.: Lets you set (the ones are not declared as SPI signal) and read the digital pins. 
DIO.Set(DIO index 0..31, value 0/1/-1) value of -1 disables output, turns to high impedance the respective DIO channel 

I modified an example script, but adding DIO.Set(31, 1) results in "Data transfer error", and WaveForms has to be restarted to recover from it.

// Pmod DA1 - AD7303

//    DIO.Set(31,1); // <-- uncommenting this line results in "Data transfer error", need to restart WaveForms to recover

for(var i = 0; i < 50 & wait(0.1); i++){
    var va = 128+sin(2*PI*i/50)*127;
    var vb = 128+cos(2*PI*i/50)*127;
    Start();
    Write(16, 0x0100 | (va & 0xFF)); // Update DAC A input register from shift register
    Stop();
    Start();
    Write(16, 0x2400 | (vb & 0xFF) ); // Load DAC B input register from shift register and update both DAC A and DAC B DAC registers outputs.
    Stop();
    
//    DIO.Set(31,0); // <-- uncommenting this line results in "Data transfer error", need to restart WaveForms to recover
    wait(0.0001);
//    DIO.Set(31,1); // <-- uncommenting this line results in "Data transfer error", need to restart WaveForms to recover

}
return "done"

Any suggestions to generate the desired signal? Any help is appreciated!

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

OK, I found the solution myself:

Pin DIO31 has the address 7, not 31.

So the following code does the trick:

// Pmod DA1 - AD7303

DIO.Set(31-24,1); // <-- DIO31 has address 7
                             
for(var i = 0; i < 50 & wait(0.1); i++){
    var va = 128+sin(2*PI*i/50)*127;
    var vb = 128+cos(2*PI*i/50)*127;
    Start();
    Write(16, 0x0100 | (va & 0xFF)); // Update DAC A input register from shift register
//    Stop();
//    Start();
    Write(16, 0x2400 | (vb & 0xFF) ); // Load DAC B input register from shift register and update both DAC A and DAC B DAC registers outputs.
    
    Stop();

    // output latch pulse:
    DIO.Set(31-24,0); // <-- DIO31 has address 7
//    wait(0.0001);  // without wait(), pulse with is approx. 0.9 ms
    DIO.Set(31-24,1); // <-- DIO31 has address 7


}
return "done"

 

Link to comment
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
×
×
  • Create New...