View previous topic :: View next topic |
Author |
Message |
cxiong
Joined: 09 Sep 2003 Posts: 52
|
Digital Pot MCP41010 |
Posted: Fri Aug 13, 2004 2:10 pm |
|
|
I am trying to control the digital pot and it won't work, when I measure the PW0 it is 2.33V, I've try to change the value by writing the setting through RS 232 port and the voltage won't change. But when I read it back what I just enter to the pot, it read back ok.
My program is follow, please help.
------------------------------------------------//////////////////////////////////////////////////////////////////////////////////////
/// //
/// //
/// //
/// Digital Pot control MCP41010 //
///
///
///
/// ---------
/// | 1 |-B0------------
/// | 6 | | ---------
/// | F | |--CS---| 4 |
/// | 8 |-C3-------------- SCK---| 1 |
/// | 7 | | 0 |
/// | 7 |-C5---------------SI---| 1 |
/// | | | 0 |
/// --------- ---------
///
/////////////////////////////////////////////////////////////////////////////////////
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#include <input.c>
#define CS (PIN_B0)
void main()
{
byte value,cmd;
output_low(CS);
while(true)
{
printf("\r\nRead or Write: ");
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
while ( (cmd!='R') && (cmd!='W') );
if(cmd=='R')
{
printf("\r\nValue: %X\r\n",SPI_READ( ) );
}
if(cmd=='W')
{
printf("\r\nNew value: ");
value = gethex();
printf("\n\r");
SPI_WRITE(0X13);
SPI_WRITE(value );
}
}
} |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
Digital POT |
Posted: Fri Aug 13, 2004 2:35 pm |
|
|
Here is the latest, it still not work.
//////////////////////////////////////////////////////////////////////////////////////
/// //
/// //
/// //
/// Digital Pot control MCP41010 //
///
///
///
/// ---------
/// | 1 |-B0------------
/// | 6 | | ---------
/// | F | |--CS---| 4 |
/// | 8 |-C3--------------SCK---| 1 |
/// | 7 | | 0 |
/// | 7 |-C5---------------SI---| 1 |
/// | | | 0 |
/// --------- ---------
///
/// _CS connect to RB0 ** Active Low
/// SCK connect to RC3
/// SI connect to RC5
/// PA0 connect to +5V
/// PB0 connect to GND
/// PW0 connect to Voltmeter.
///
/////////////////////////////////////////////////////////////////////////////////////
#include <16f877.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // Jumpers: 8 to 11, 7 to 12
#include <input.c>
#define CS (PIN_B0)
void main()
{
byte value,cmd,spi;
output_high(CS);
setup_spi(SPI_MASTER | SPI_CLK_DIV_4);
while(true)
{
printf("\r\nRead or Write: ");
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
while ( (cmd!='R') && (cmd!='W') );
if(cmd=='R')
{
spi = SPI_READ();
printf("\r\nValue: %X\r\n",spi );
}
if(cmd=='W')
{
printf("\r\nNew value: ");
value = gethex();
printf("\n\r");
output_low(CS);
SPI_WRITE(0X13);
SPI_WRITE(value );
}
}
} |
|
|
ajt
Joined: 07 Sep 2003 Posts: 110
|
Digital Pot MCP41010 |
Posted: Fri Aug 13, 2004 8:08 pm |
|
|
Try these:
Code: |
// define CS_PIN CS active low pin in main source file and set to high in main()
#separate
//----------------------------------------------
void initDigPot(int InitialValue)
//----------------------------------------------
{
setup_spi(SPI_MASTER | SPI_H_TO_L | SPI_CLK_DIV_16);
output_high(CS_PIN);
DigPot(InitialValue);
}
#separate
//----------------------------------------------
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 |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
|
Posted: Mon Aug 16, 2004 7:36 am |
|
|
Do I need to do the samething to read the pot value?
example:
:
:
output_low(CS);
spi_write(0x13); ??? Do I need this line to read the current pot value?
spi=spi_read();
output_high(CS);
:
:
Please advice. |
|
|
ajt
Joined: 07 Sep 2003 Posts: 110
|
|
Posted: Wed Aug 18, 2004 6:36 am |
|
|
A reading of the spec sheet for the part will show that it does not have a read command. The spec lists these commands:
1. Write a new value to the potentiometer data
register(s).
2. Cause a channel to enter low power shutdown
mode.
3. NOP (No Operation) command.
Why do you want to read the value? You wrote it into the part so you know what it is. _________________ Al Testani |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
|
Posted: Wed Aug 18, 2004 10:05 am |
|
|
I want to read it because everytime I power cycle the unit, the pot value is change/reset(previous enter value) was gone, I have to enter the value everytime.
I would like to do read to see if its value still active. Beside that there is a
SPI_READ() function in the compiler manual.
Give me direction of how to keep the entered value all times unless I decide to change. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Aug 18, 2004 11:48 am |
|
|
This is why I hate it when people double post!
You can't read the value from the pot. You could ask as many people as you like but the fact remains that you can't do it. See here for why:
http://www.ccsinfo.com/forum/viewtopic.php?t=20243 |
|
|
ajt
Joined: 07 Sep 2003 Posts: 110
|
|
Posted: Wed Aug 18, 2004 9:37 pm |
|
|
cxiong wrote: | I want to read it because everytime I power cycle the unit, the pot value is change/reset(previous enter value) was gone, I have to enter the value everytime.
I would like to do read to see if its value still active. Beside that there is a
SPI_READ() function in the compiler manual.
Give me direction of how to keep the entered value all times unless I decide to change. |
As multiple people have told you (in crossposts as well) you CANNOT read from this device. Whether there is a CCS SPI_read function is irrelevant if the device can't be read. You would be better served to stop asking this question over and over again and get on with solving the problem you have.
The solution is to write the pot value to the pot and to Data EEPROM everytime. Whenever the processor starts, read the EEPROM and restore the pot value using the routines I have given you. _________________ Al Testani |
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 19, 2004 2:26 am |
|
|
cxiong wrote: | I want to read it because everytime I power cycle the unit, the pot value is change/reset(previous enter value) was gone, I have to enter the value everytime.
I would like to do read to see if its value still active. Beside that there is a
SPI_READ() function in the compiler manual.
Give me direction of how to keep the entered value all times unless I decide to change. |
Assuming that you do not change the value very often, when you write it to the chip, write it to the processors EEPROM as well. Whenever the system wakes from a power failure, read the EEPROM, and write this value to the chip.
The SPI functions are _general purpose_. They work with chips that do support reading as well as writing, _which this one does not_.
Best Wishes |
|
|
cxiong
Joined: 09 Sep 2003 Posts: 52
|
|
Posted: Thu Aug 19, 2004 6:14 am |
|
|
Thanks for every one's input. I will try to use the EEPROM to
record the pot setting. I will search to see if there is any good
subroutine that I can use specially the EEPROM.
If anyone has a subroutine that work, please let me know.
I plan to use the internal EEPROM of the processor. |
|
|
rwyoung
Joined: 12 Nov 2003 Posts: 563 Location: Lawrence, KS USA
|
|
Posted: Thu Aug 19, 2004 8:01 am |
|
|
If the PIC has built-in EEPROM use the functions supplied by CCS.
Search the CCS help file for:
write_eeprom
and
read_eeprom
Also read the datasheet for your PIC very carefully reguarding the use of its internal EEPROM. _________________ Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month! |
|
|
|