CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Need help with SPI Digital Pot...
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Tue Dec 30, 2003 5:47 pm     Reply with quote

Ok, I'm going to test that new code now mark... I have a feeling though. I'm not sure why this has to be such a big deal... Its frustrating though. I wonder is that code you posted the same as what CSS is doing or where its different...

Anyhow, I'm about to test that last mark code and this:
Code:

#include <16F872.h>
#fuses RC,LVP,NOWDT,NOPROTECT, PUT, NOBROWNOUT
#use delay(clock=1000000)

void main() {

 output_high(PIN_C1);
 output_high(PIN_C3);
 setup_spi(spi_master | 0x4000 | spi_clk_div_16);
 delay_us(20);

 output_low(PIN_C1);
 spi_write(17);         
 spi_write(63);         
 output_high(PIN_C1);

 while(1){
 } //eow
} //eom


I went back and read some basic SPI examples that people have gotten to work and it seems like some are nowhere near as complete as the one I just posted... What Gives!?

Well, I'l test these in a second... By the way: How should I be testing these on the pot ?? I CAN just DMM two pins right ?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 30, 2003 6:53 pm     Reply with quote

Well, what I did was read the datasheet for the pot. From there, I just wrote the code that should work. I am pretty sure that it should work. If not, then something else is wrong. As for reading the pot, a DMM should work. If in doubt, you can connect A to Vdd and B to Vss and measure the voltage from the wiper.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

YAYYYYY!!!! and then... oh.... crap,
PostPosted: Tue Dec 30, 2003 8:30 pm     Reply with quote

Mark/Everyone, it works!!! But now so does the other (my) code. I think it was the setting clock and CS to high at first.

But now I have another problem... The whole reason I'm doing this pot stuff is to be able to set a variable 'load' on a wire... I have this system where every switched pressed makes the signal wire hit a resistor, that wire is then read by an ADC to figure out what resistor (what button) was hit.

Get it ? I need the pot to simulate the different resistors b/c I want to get rid of these buttons... But its important to note that this system doesnt send 5V into a switch and then read the ground wire, no instead it sends 5V up into the switch and it 'monitors' that wire (it could give a crap about ground)

So here is what I did... I hooked the 5V signal wire upto my B and then its signal ground wire upto W... So I figured this would be like the sig wire running into a resistor of X value. But I couldn't fool that original adc type system (which i dont have access to look at or modify, I'm assuming its an adc system, it acts like one)... Anyhow, if anyone follows still, What am I doing wrong?

To be honest I'm not really sure why there is a A, B and W... I only see the need for 2. Am I even close to getting this to work ?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 30, 2003 9:01 pm     Reply with quote

Forget about the pot for now. Can you fool the system with just a resistor connected? There must be another resistor somewhere connected for the adc to work. There has to be a divisor to get different voltages. You might try pressing the buttons and measuring the voltage at the adc. Once you know this, you will be able to remove the old buttons and use your new pot. You will most likely need to connect A to Vdd and B to Vss. The W will then go into the adc.
ajt



Joined: 07 Sep 2003
Posts: 110

View user's profile Send private message

PostPosted: Tue Dec 30, 2003 9:48 pm     Reply with quote

As has been pointed out, the CS line must be high and only go low during the command sequence. I use the following code which works fine:

Code:
// define CS_PIN in main source file and call initDigPot early in main()

//----------------------------------------------
void initDigPot(int InitialValue)
//----------------------------------------------
{
   setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
   output_high(CS_PIN);
   DigPot(InitialValue);
}


//----------------------------------------------
void DigPot(int value)
//----------------------------------------------
//used for MCP41xxx Microchip digital pot
// 0x00 = wiper at PB0, 0xFF wiper at PA0
{
   output_low(CS_PIN);
   delay_us(1);
   spi_write(0x13);  //command byte to write data to pot
   spi_write(value);
   delay_us(1);
   output_high(CS_PIN);
}

_________________
Al Testani
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Caution with that digital pot!!
PostPosted: Wed Dec 31, 2003 8:27 am     Reply with quote

I understand exactly what you are trying to do.
But DO NOT put 5V on A,B or W of that pot with out a current limiting resistor!!
It will burn out!!

I did a project like this some time back.
The problem that you are going to run in to is that with the current limitations of the digital pot you will not be able to get a full voltage (0V to 5V) swing.
I have used the digital pots at they turn out to be more of a pain in the neck than they are worth!

Ok with all of that Mark has you looking in the right place.
You need to get the old system up and running and measure the voltage for each key pressed.
Then to make life so much easer I would use a good digital to analog converter like the DAC7611 it is a Burr-Brown/TI part. You can get it at Dig-Key. It use the same interface to your PIC as the pot. But I think that you will have to use Marks bit-banging code to send it the 12 bit required or maybe not you would need to look at that.
The system-to-system interface then would only be the output of the new DAC to the old ADC and a ground wire from the old system to the new system.
You will have to have the two system grounded to each other.

Will think about that.

Tom
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 10:33 am     Reply with quote

How about connecting resistors to some open collector digital outputs? If you have enough PIC pins you might be able to just connect resistors from the sense line to the PIC pins which are set as HiZ or output low (or output high?). A binary weighted set of resistors gives you a cheap DAC, or use a dedicated resistor and pin for each pushbutton simulated.

If you don't have enough PIC pins there are plenty of serial to parallel output chips.
_________________
The search for better is endless. Instead simply find very good and get the job done.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 10:42 am     Reply with quote

The current limmiting thing IS somthing I thought of, BUT this isnt really an open system where I think it would be a problem... ie: This original system can only allow .20mA to be drawn... I think the pot says it can handle .1mA (maybe, i thought i saw that)...

And there is no way to connect a resistor path up, its WAY to many... We're talking like 11 possible resistances, so I use one digital pot takes up 3 pins on the pic and this way if my system changes resistances a software flash will fix it. I thought of a hardware design, I don think it'll work, too big and limmiting.

I need to figure out why the digital pot isnt putting a load on the signal wire for that old systems' ADC to read... I DMM'd the wire a little along the way and it 'read' about right, but I think the orig system is looking for X volt at .2mA and I didnt check what was actually going through, but I have a feeling it wasnt .2mA. But this should matter for an ADC no? Isnt the ADC just going to read voltage no matter what mA its at ?

I need to do some more tests... But I'm bummed cause I thought for sure I could use the pot to place a 'load' on that wire... Does my goal make sense? I'll test it some more today,
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 31, 2003 12:18 pm     Reply with quote

Quote:

But DO NOT put 5V on A,B or W of that pot with out a current limiting resistor!!
It will burn out!!


The wiper current is good for 1ma. There is not a problem putting Vdd on A and GND on B. Where you have to be careful is the wiper. You do not want to draw more than 1ma through it. If you are connecting this to the input of an ADC then you should be okay since the input impedance is very high. However, you might have to use an Op-amp to buffer the signal for the ADC to work correctly. Refer to the ADC datasheet and look at the source impedance parameter.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 1:10 pm     Reply with quote

Ok.... I learned stuff.

If I dmm the signal wire I see that its a 5V and 2mA (not .2 like i wrote before), does this mean its MAX draw can be no more then 2mA? Cause I cant open the original system to look at the processor, but I'm guessing that its buffereing that signal since its being read by its own ADC. And they cant buffer it after the resistors and before the adc cause that would throw everything off.

I made up a little diagram of whats going on, the first block is what the original system does. That will box with the resistors in it is my oddly made multi-position switch. The 2nd is what I want to do (get rid of the switches) and the third is the 2nd but with a current limiting resistor inline, which i THINK would be a problem cause it would throw off my entire system, since it would mess up the adc readings.



The datasheet for the pot says the max wiper current is 1.0mA (i think thats what it says... I'm pretty dumb, so i dont really know). It looks like my signal coming in is buffered to 2.0mA... So if put a resistor inline, where the adc would normally read 2.5V its going to read like 1.75V and nothing will work. I think... I could have this all wrong.

Does this all make sense to anyone? If I try and cut down the amperage coming into the pot, I'l throw off the interal adc in the processor...

Ok so... The processor is always reading the signal load, so it knows you are not pressing any switches when its adc reading it own wire and sees 5.0V, when the internal adc reads 4.00V it knows the signal was diverted into a 2k resistor. I want to make my pot into 2k so the internal adc reads 4V. With an inline resistor to limit the current coming into the pot I couldnt ever get back to 4V... I'de have a top of like 3V.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 3:12 pm     Reply with quote

I guess what I'm wondering is...


If you have a 5V at 2.0mA wire and put a 5K resistor inline and measure it, it still says 5V on my DMM, but the amperage is now 1.0mA (which is what I want to do)...

But when I pass 5V through the resistors in my switch I measure different voltages (which is what its supposed to do)... I'm kinda confused as to why...

in other words:

does a resistor on a 5V wire drop the voltage down or does it cut the amperage down ? Or does it depend on how you measure it... (ie: I'm using a DMM and the system is using an ADC)


Regardless, I need to cut the power coming into my POT down, but cant effect the load that is read by the processor on that wire. This seems to be a problem.

Thanks,
Ttelmah
Guest







PostPosted: Wed Dec 31, 2003 3:41 pm     Reply with quote

iso9001 wrote:
I guess what I'm wondering is...


If you have a 5V at 2.0mA wire and put a 5K resistor inline and measure it, it still says 5V on my DMM, but the amperage is now 1.0mA (which is what I want to do)...

But when I pass 5V through the resistors in my switch I measure different voltages (which is what its supposed to do)... I'm kinda confused as to why...

in other words:

does a resistor on a 5V wire drop the voltage down or does it cut the amperage down ? Or does it depend on how you measure it... (ie: I'm using a DMM and the system is using an ADC)


Regardless, I need to cut the power coming into my POT down, but cant effect the load that is read by the processor on that wire. This seems to be a problem.

Thanks,

What you need, is the top of the pot connected to a reference voltage below 5v (most become non linear, if driven from a voltage that matches the supply - say 2.5v), the bottom of the pot connected to 0v, and the wiper connected to the input of an op-amp, running as a unity gain buffer. Then the output of the op-amp, will adjust from 0v to ((2.5/256)*255)v for the different values.
The 'downside', is that any voltages picked up on the wires between the transmitter and the ADC, will result in errors, as will the resistance of the wires themselves. Hence you would be better off, using the pot to generate a variable current source, and then connect this across a resistor at the ADC end.
It is better to run these pots as 'potential dividers', feeding into a small load, since typically the endpoint resistance is fairly innaccurate, and any change in load will result in errors.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Dec 31, 2003 4:34 pm     Reply with quote

Draw a picture of how you are measuring with the DMM. You explainations do not make much sense unless the 5V you are measuring is the source (which should always be 5V unless you overload it).

Have you taken voltage measurements at the ADC with the different switches pressed?
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 4:59 pm     Reply with quote

Ttelmah.... holy crap. I have no idea what all that means... But I've only read it twice so far, and like I said, I'm pretty slow so it'll take awhile. I do like pretty pictures though Smile

Mark... I'll make a diagram of the whole system.

To clear up what i'm doing: The project is to get rid of these switches, this entire system is an engine on a boat, but its pretty much a car engine. So the system that I can not access is a engine controller (modern one).

Its all 5V, and it looks like i was right about the controller buffering the signal so that no more then 2.0mA can run in that wire. So i just hooked up my non working example and saw that I had 2.mA running into my pot... am I right that this thing can take no more then 1.0mA ? Cause its taking 2 for right now at least (i know it'll burn up eventually, just testing)

I'm going to try and make a better code example, flash it, go out hook it up and see if I cant get the idea to work. Even though this does mean letting 2mA go throught the pot. (Which does still work btw)
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Wed Dec 31, 2003 5:37 pm     Reply with quote

Thelmah,

I tried reading over your thing again. I might (prolly) be mistaken, but I think by hooking the pot upto an op.amp like you said I'de be making a sortof DAC... Which isnt what i want to do.

I thought at first that this thing is sending a 5V siganl into a set of resistors and checking the other (ground) wire to see what value comes back. If this were the case, I could use a DAC and just send the imaginally signal (5V, 3.3, 1.0, etc) right into the wire... Not the case though,

The other wire doesnt even return directly to the processor, its chassis ground. So (and I thought this was clever) they ADC thier own wire to save running on wire back to the controller. So unless I totally missed the point of what you are saying (likely) I'm still thinking about the potentio.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group