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

AD8403 digital pot routine

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







AD8403 digital pot routine
PostPosted: Tue May 06, 2003 1:55 am     Reply with quote

Hello all,
I am trying to put together the software to control an AD8403 digital pot for a filter project.I'm using a 16f628 or 16f877 PIC.
How would I modify the example included with the PCM compiler
(AD8400 included below) so that I can increment the Values of each of the 4 pots one at a time ( eg increment rdac1 to full resistance, then rdac2, then rdac3 annd so on).
Any help would be appreciated, thank you.
///////////////////////////////////////////////////////////////////////////
//// Library for a AD8400 ////
//// ////
//// init_pots (); Sets all of the pots to 0 ////
//// ////
//// set_pot (pot_num, new_value); Sets pot pot_num to new_value ////
//// ////
///////////////////////////////////////////////////////////////////////////
//// (C) Copyright 1996,1997 Custom Computer Services ////
//// This source code may only be used by licensed users of the CCS C ////
//// compiler. This source code may only be distributed to other ////
//// licensed users of the CCS C compiler. No other use, reproduction ////
//// or distribution is permitted without written permission. ////
//// Derivative programs created using this software in object code ////
//// form are not restricted in any way. ////
////////////////////////////////////////////////////////////////////////////

#define RST1 PIN_B0
#define CLK PIN_B1
#define DI PIN_B2
#define NUM_POTS 1

byte pots;

set_pot (int pot_num, int new_value)
{
byte i;
byte cmd[2];

pots = new_value;
cmd[0] = pots;
cmd[1] = 0;

for(i=1;i<=6;i++)
shift_left(cmd,2,0);

output_low(CLK);
output_low(RST1);

delay_us(2);
for(i=1;i<=10;++i)
{
output_bit(DI, shift_left(cmd,2,0));
delay_us(2);
output_high(CLK);
delay_us(2);
output_low(CLK);
delay_us(2);
}
output_high(RST1);
}

void init_pots ()
{
pots = 0;
}

Regards,
David Briscoe
London,England
___________________________
This message was ported from CCS's old forum
Original Post ID: 14204
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: AD8403 digital pot routine
PostPosted: Tue May 06, 2003 1:33 pm     Reply with quote

:=How would I modify the example included with the PCM compiler
:=(AD8400 included below) so that I can increment the Values of each of the 4 pots one at a time ( eg increment rdac1 to full resistance, then rdac2, then rdac3 annd so on).
:=Any help would be appreciated, thank you.
:=
:=#define RST1 PIN_B0
:=#define CLK PIN_B1
:=#define DI PIN_B2
:=#define NUM_POTS 1
:=
:=byte pots;
:=
:=set_pot (int pot_num, int new_value)
:= {
:= byte i;
:= byte cmd[2];
:=
:= pots = new_value;
:= cmd[0] = pots;


I think you can make it work with the AD8403 by
doing the following changes:
<PRE>
// cmd[1] = 0; // Comment this line out.
cmd[1] = pot_num; // Add this line
</PRE>

:=
:= for(i=1;i<=6;i++)
:= shift_left(cmd,2,0);
:=
:= output_low(CLK);
:= output_low(RST1);
:=
:= delay_us(2);
:= for(i=1;i<=10;++i)
:= {
:= output_bit(DI, shift_left(cmd,2,0));
:= delay_us(2);
:= output_high(CLK);
:= delay_us(2);
:= output_low(CLK);
:= delay_us(2);
:= }
:= output_high(RST1);
:= }
:=
:=void init_pots ()
:={
:= pots = 0;
:=}
___________________________
This message was ported from CCS's old forum
Original Post ID: 14217
David Briscoe
Guest







Re: AD8403 digital pot routine
PostPosted: Thu May 08, 2003 1:49 am     Reply with quote

:=:=How would I modify the example included with the PCM compiler
:=:=(AD8400 included below) so that I can increment the Values of each of the 4 pots one at a time ( eg increment rdac1 to full resistance, then rdac2, then rdac3 annd so on).
:=:=Any help would be appreciated, thank you.
:=:=
:=:=#define RST1 PIN_B0
:=:=#define CLK PIN_B1
:=:=#define DI PIN_B2
:=:=#define NUM_POTS 1
:=:=
:=:=byte pots;
:=:=
:=:=set_pot (int pot_num, int new_value)
:=:= {
:=:= byte i;
:=:= byte cmd[2];
:=:=
:=:= pots = new_value;
:=:= cmd[0] = pots;
:=
:=
:=I think you can make it work with the AD8403 by
:=doing the following changes:
:=<PRE>
:=// cmd[1] = 0; // Comment this line out.
:=cmd[1] = pot_num; // Add this line
:=</PRE>
:=
:=:=
:=:= for(i=1;i<=6;i++)
:=:= shift_left(cmd,2,0);
:=:=
:=:= output_low(CLK);
:=:= output_low(RST1);
:=:=
:=:= delay_us(2);
:=:= for(i=1;i<=10;++i)
:=:= {
:=:= output_bit(DI, shift_left(cmd,2,0));
:=:= delay_us(2);
:=:= output_high(CLK);
:=:= delay_us(2);
:=:= output_low(CLK);
:=:= delay_us(2);
:=:= }
:=:= output_high(RST1);
:=:= }
:=:=
:=:=void init_pots ()
:=:={
:=:= pots = 0;
:=:=}
Thank you PCM programmer, I will try your suggestion.
Dave Briscoe.
___________________________
This message was ported from CCS's old forum
Original Post ID: 14251
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