View previous topic :: View next topic |
Author |
Message |
mshearer
Joined: 12 Jan 2009 Posts: 33
|
digipot problem |
Posted: Mon Jun 08, 2009 3:26 am |
|
|
Hi
I'm using an 18f4520 and trying to control a digitpot. In general this works perfectly for me.
I can configure the digipot at the start of my project to adjust a adc input to exactly 2.5V.
However I have made a small GUI to manually adjust the digipot, allowing me to enter any hex value and watch the change in the voltage.
My problem is, while I can enter 0xFF and get 5V. If I then enter 0x2F, I should get 2.5V. Instead I get 3.99V then if I send again 2.5V.
Seems when coming back down through the voltages the digipot takes two attempts.
my digipot function:
Code: | void set_digipot_bias(uint8_t digiPotValue)
{
reg_SSPCON1 = 0x20;
reg_SSPSTAT = 0x40; // set SPI to txd on rising edge of SCK
bit_RE2 = FALSE; // Chip select the digipot
reg_SSPBUF = 0x00;
while(!bit_BF);
reg_SSPBUF = digiPotValue;
while(!bit_BF);
bit_RE2 = TRUE; // de-select the digipot
}
|
Any help would be really great,
Matt
Last edited by mshearer on Mon Jun 08, 2009 10:26 am; edited 1 time in total |
|
|
Ttelmah Guest
|
|
Posted: Mon Jun 08, 2009 5:02 am |
|
|
It'd help if you told us 'what digipot'.....
Best Wishes |
|
|
mshearer
Joined: 12 Jan 2009 Posts: 33
|
|
Posted: Mon Jun 08, 2009 10:25 am |
|
|
ah very sorry AD8400 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jun 08, 2009 11:27 am |
|
|
Use the CCS AD8400 driver instead of your code and see if it works:
Quote: | c:\program files\picc\drivers\ad8400.c |
|
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Mon Jun 08, 2009 2:46 pm |
|
|
mshearer wrote: | ah very sorry AD8400 |
How did you wire the pot up? As a potentiometer or as a rheostat (tying the wiper to either A or B)? I have used this part before and have not had issues with it. |
|
|
Guest
|
|
Posted: Tue Jun 09, 2009 7:43 am |
|
|
got it sorted.
Stupidly enough it wasn't the digipot really, just the delay i was leaving between digipot settings and reading the adc. changing from 2ms to 200ms fixed all my problems. |
|
|
Guest
|
|
Posted: Tue Jun 09, 2009 3:52 pm |
|
|
Hi all,
The AD8400.c file in my driver directory seems incomplete. It looks like it's supposed to work with 'N' pots, but it's clearly coded for only a single unit. The InitPot function is also incomplete. My compiler is about a year old. Is there a later version of the AD8400.c or is completing it left as an exercise for the user?
Dave |
|
|
|