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 support@ccsinfo.com

Potentiometers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ronald
Guest







Potentiometers
PostPosted: Tue Mar 06, 2007 2:06 pm     Reply with quote

I'm kind of newie in PIC. Do you guys think if it's possible to use some Pic as a digital Potentiometer. I would like to control the value of a Resistor of a range from 20k to 150k. Can I do that with PIc?
Thank You.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 06, 2007 2:22 pm     Reply with quote

My advice is to buy one. They're cheap.

Go to Digikey and type in the search box: Digital Pot
http://www.digikey.com/
Then when you get the next page, select the tickbox for Items in Stock
and click Search Again.

It lists 749 of them.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Mar 06, 2007 3:17 pm     Reply with quote

A PIC can take an analog signal and turn it into a digital value so it can process it but I would recommend not trying to create an analog value with a PIC. Like PCM stated, it would be better to use a digital POT to generate your analog signal. There are many available that interface in various ways to the PIC, ie. I2C, SPI, Parallel.... They come in many different values with different resolutions.

Ronald
ROnald
Guest







PostPosted: Wed Mar 07, 2007 1:12 pm     Reply with quote

Thanks, I found the digital potenciometer MPC41010.
I did a code to use it. But it didn't work. I can compile , but when I tested it at Proteus nothing happend. I debugged and It's Like never left the second line , it didn't "enter"at the main program.
Could guys Help me please to find where It's wrong. I can't find. I connected pin bo to SI( MPC41010) , pin b1 to SCk and pin b2 to CS.
Thanks for the heelp.
Here's the code:

#include <16f877.h>
#Use delay(clock=4000000)
#fuses NOWDT , XT , PUT ,NOPROTECT , NOBROWNOUT , NOLVP , NOCPD ,NOWRT, NODEBUG

#define spi_clk pin_b1
#define spi_dta pin_b0
#define spi_cs pin_b2

void spi_write_bit (boolean bit);
void spi_write_byte(byte data);

void main (void)
{
int data;
set_tris_b(0);
delay_ms(10);
while(1)
{
data=10;
spi_write_byte(data);
delay_ms(15000);

}


}

void spi_write_bit (boolean bit)
{
output_bit(spi_dta,bit);
output_high(spi_clk);
delay_us(1);
output_low(spi_clk);
}
void spi_write_byte(byte dado)

{
int conta=8;
while (conta)
{
spi_write_bit((shift_left(&dado,1,0)));
conta--;
}

output_float(spi_dta);

}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 07, 2007 1:18 pm     Reply with quote

Quote:
I found the digital potenciometer MPC41010.
I did a code to use it. But it didn't work

Why are you writing your own driver ? CCS has a driver. It's right here:
Quote:
c:\program files\picc\drivers\mcp41010.c
Ronald
Guest







PostPosted: Wed Mar 07, 2007 2:22 pm     Reply with quote

Have someone ever use MCP41010 with PIC16f877? I use the code from c:\program files\picc\drivers\mcp41010.c , and this simple main fuction:

void main (void)
{
int data;

delay_ms(10);


data=100;
set_pot(data);
while(1);


}

And I test a simple voltage divisor , I conected pin PAO to a Power , Pin PWO to a resistor that it's connected to ground , and PBO to ground. And I checked the voltage between the PWO and the resistor . It's Stay all the same even when I change the data value. Please Help Me.
Thank you so much for your Help
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 07, 2007 2:36 pm     Reply with quote

In your original code you have these settings:
Quote:

#define spi_clk pin_b1
#define spi_dta pin_b0
#define spi_cs pin_b2

These are your hardware connections between the PIC and the MCP41010.

The CCS driver file, mcp41010.c, has a list of pin connections at the
start of the file. You need to edit the driver file and change the #define
statements so they match your hardware connections.

Do it like this:
Code:

#define CS    PIN_B2
#define SCLK  PIN_B1
#define SI    PIN_B0
Ronald
Guest







PostPosted: Wed Mar 07, 2007 3:26 pm     Reply with quote

I used:
#define CS PIN_B4
#define SCLK PIN_B2
#define SI PIN_B1

And connected right to the Pot, but nothing happended. Have someone ever simulate that?
Ronald
Guest







PostPosted: Wed Mar 07, 2007 6:15 pm     Reply with quote

I found what's wrong . I should have put shutdown_pot (); before using the digital pot.
Ronald
Guest







PostPosted: Thu Mar 15, 2007 10:52 am     Reply with quote

Have someone ever simulate or use the Dig Pot MCP41010? I'm using the ccs library for using it , the functions void set_pot (int data) and void shutdown_pot (). When I want to set the Pot just one time it works , like:

int data;
shutdown_pot ();
delay_ms(10);

data=220;
set_pot(data);

but , if I try to set the value 2 times like


int data;
shutdown_pot ();
delay_ms(10);

data=220;
set_pot(data);
delay_ms(5000);
shutdown_pot ();
delay_ms(10);

data=220;
set_pot(data);

It only set the first time , it doesn't change the value . I don't know if it's a Proteus problem , that the only component that can change with time it's the simple Pot or if it's something with the code. Have someone ever used that?
Ronald
Guest







PostPosted: Fri Mar 16, 2007 2:34 pm     Reply with quote

Please , somebody help me!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 2:45 pm     Reply with quote

This is not a Proteus board. Get some real hardware and we can
probably do something.
Ronald
Guest







PostPosted: Fri Mar 16, 2007 7:16 pm     Reply with quote

What you mean by real hardware ?Sorry I'm start learning about one month ago.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Mar 16, 2007 8:27 pm     Reply with quote

In an earlier post you said this:
Quote:
but when I tested it at Proteus

So I assume that everything you're doing is in Proteus.
Proteus is a simulator. It has its own quirks and bugs.

By "real hardware", I meant a physical MCP41010 chip mounted
on a PIC prototype board.

Basically, I meant to say that (at least for me) I can't help
to trouble-shoot Proteus problems. In other words, I can
help solve the problems with PICs and Microchip I.C.'s but
I can't help with Proteus.

Obviously, there are one or two people on this board who
do own Proteus and can help. So maybe I shouldn't have
made the statement in my post. But because you are using
Proteus instead of real hardware, you limit the number of
people on this forum who can really help you. Only people
who own Proteus are able to confirm if a problem is a bug
within Proteus.
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Sun Mar 18, 2007 12:11 pm     Reply with quote

I tested the MCP41010 model in Proteus and confirmed the behaviour you described.

I contacted Labcenter and they also confirmed that it was a bug in the model and have fixed it. If you check out the "Bug Reports" section of their forum you will see the new files have been posted. I tested the new model and it works.

Note that if you aren't a registered user, you will not see this section of the forum. Just like CCS code, I can't pass that code to you, so you will have to obtain it from the company yourself.

A good catch on your part.

Rod
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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