NI Home > Community > NI Discussion Forums

Instrument Control (GPIB, Serial, VISA, IVI)

Showing results for 
Search instead for 
Do you mean 
Reply
Member
dalvares
Posts: 27
0 Kudos

Rs-232 digital potentiometer using SPI and USB-6008

Hi All, 

 

Although I have a little bit of experience with labview I am fairly new to serial communication. I want to use my serial port and if needed a USB 6008 to control a digital potentiometer MCP4161. Unfortunately I don't have the budget to invest in other acquisition hardware so might have to work with what I have. 

 

 I see that it needs 3 inputs in order to change the resistance: 

1) Clock in

2) Data read enable

3) The bits that correspond to wiper position (resistance). 

 

I understand I can't get the clock output from the USB-6008? However is it possible to get this from the serial port? I could use a digital line on the USB-6008 as the read enable. The bits from the wiper position come from the serial port? (Does anyone have any suitable examples on this? I presume it would use VISA?)

 

Thanks in advance for your help. I think with a kick start I should be able to come up with a solution

 

 

Cheers, 

Darren 

Trusted Enthusiast
Albert.Geven
Posts: 3,380
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

you can generate a clock with the 6008 by using an extra pin and change the output on that pin twice as fast as on the communication pins.

In fact software timing but SPI is not very critical on clock timing

greetings from the Netherlands
Member
dalvares
Posts: 27
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

Thanks Albert for your prompt suggestion. 

 

Just to clarify. do you mean using two digital output lines? Could I just use one and send it high and low based on the frequency of my loop? (This is what you mean by software timing? ) Also with the output from the rs-232 port is there any examples you can point me to? 

 

Thanks, 

Darren

Knight of NI
Posts: 18,064
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

The SPI protocol requires 4 lines: Clock, MISO, MOSI, and Enable. If you are not reading data from a device then you can drop MISO. As Albert mentioned, you can use the "bit-banging" approach to create the clock and data out (MOSI) signal. The enable line can be a separate line.

 

I do not understand what you mean by serial out. The RS-232 lines have different voltages on them than what the digital pot would expect, since the voltages for SPI are not the same as for RS-232.

Member
dalvares
Posts: 27
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

Hi, Finally understand what you mean. However I had a go at writing some code with little success :smileysad:

 

Attached is the code I wrote and the data sheet for the device I am trying to program. Any thoughts on where I could possibly going wrong would be helpful. 

 

Thanks, 

Darren

Trusted Enthusiast
Albert.Geven
Posts: 3,380
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

Hi

I did not check your complete program but the doubling of the data anyhow is wrong.

You best can do that where you write the outputs. Instead of writing out once write in an extra  for loop inside the one you have now. the clock once straight and once inverted and twice the same data.

greetings from the Netherlands
Member
dalvares
Posts: 27
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

Hi Albert, 

 

Once again thank you for your prompt reply. I dont completely understand your message and why looping through an array with digital values is different from looping through in a while loop and setting the values individually ? If this is what you mean? 

 

So to make this process a little easier I improved the commenting on the code a little more. Also in the MCP data sheet I basically used the timing diagram on Pg 42 Figure 6.4. 16 bit SPI waveform mode 0,0. Relevant txt is from pg 45-49

 

I assume the first 6 bits are command bits and then the 7th bits is nothing and the final bit 0 is nothing (Dont understand why there are 9 bits in the diagram when it is only an 8 bit resistor). 

 

So my pot is a 10k pot. When I run the code as is with a requested value of 6K its ok. But every other value is incorrect. I have a feeling it has to do with the order in which I am outputing each bit but again I am unsure what is wrong. 

 

Thanks again for your help. 

 

Cheers, 

Darren 

 

 

Trusted Enthusiast
Albert.Geven
Posts: 3,380
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

Hi

 

to give you an idea what I meant I changed your program but did not check it against the pot meter spec.

I expect some bits to be wrong because of my simplicity in converting your program but the idea makes it simpler.

One of the problems I had with the fact that the clock was not generated as a real clock in the beginning and the end.

This can better be solved by writing digital bits before and after the for loop that writes now.

anayhow it show what I mean.

 

greetings from the Netherlands
Member
ankitsharma
Posts: 19
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

sir,i am also using mcp41010..your write digital pot programme can not work..and please give me connection diagram and programme for it.

Member
ankitsharma
Posts: 19
0 Kudos

Re: Rs-232 digital potentiometer using SPI and USB-6008

[ Edited ]

i am using spi signal for it..