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

AD7528JN

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



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

AD7528JN
PostPosted: Tue May 03, 2011 3:19 am     Reply with quote

Deal All
I am using AD7528JN along with PIC to convert digital to analog outputs. However I want to confirm if I am using the chip in the right way. Here is my code.

Code:


#include <18F4620.H>

#fuses HS,PROTECT,PUT,NOBROWNOUT,NOLVP,NOWDT
#use delay(clock=20000000)

#byte PORTB = 0xf81
#byte TRISB = 0xf93

#byte TRISC = 0xf94
#byte PORTC = 0xf82


#bit WR = PORTC.0
#bit CS = PORTC.1
#bit DAC = PORTC.2


void main(void)
{
int i;
int j;
set_tris_c(0x00);
set_tris_b(0x00);
i=128;

   WR=0;delay_ms(100);
   CS=0;delay_us(100);

   DAC=0;delay_us(50);
   PORTB=128;   
   DAC=1;delay_us(50);
   PORTB=128;


   
//   WR=1;

delay_ms(2000);
while(1)
{

   for(i=100; i<=140; i=i+1)
   {
   DAC=0;PORTB=i;delay_us(10);
   DAC=1;PORTB=128;delay_us(10);
   delay_ms(250);
   }


   for(i=100; i<=140; i=i+1)
   {
   DAC=0;PORTB=128;delay_us(10);
   DAC=1;PORTB=i; delay_us(10);
   delay_ms(250);
   }



}
}


Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue May 03, 2011 11:19 am     Reply with quote

I would have made it into a routine, called write_dac() or ad7528_write().
Then call the routine in main(). Pass the dac value as a parameter.
Example of how it would be called:
Code:

write_dac(value);
arunkish



Joined: 23 Dec 2008
Posts: 83

View user's profile Send private message

PostPosted: Tue May 03, 2011 10:35 pm     Reply with quote

Dear PCM Programmer
Thank you for your advice. I want to know if the delay and the way in which I am passing the value to the DAC port is right or not.

Thanks
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed May 04, 2011 12:47 am     Reply with quote

Quote:
I want to know if the delay and the way in which I am passing the value to the DAC port is right or not.

Not exactly. You have enabled /CS and /WR permanently and are only toggling the select line. So both DAC outputs will show glitches. You should preferably strobe the /WR line low after setting a new value. /CS can be hardwired and don't need a separate pin, as long as you don't intend to drive multiple devices.

Code:
DAC=0;PORTB=val_a;WR=0;WR=1;delay_us(10);
DAC=1;PORTB=val_b;WR=0;WR=1;delay_us(10);
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