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 CCS Technical Support

Need a fast way of writing to multible SPI DACs

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



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

Need a fast way of writing to multible SPI DACs
PostPosted: Mon Feb 20, 2006 12:20 pm     Reply with quote

I've got a few DAC's that are adressed over SPI. I need to write to all of them at different times. My idea was to make an option in the write command to address each one's CS pin. But the problem is I can not output to a variable.

Like this:
Code:

void DACWrite(int addr, int value, int cs) //Add param to change CS
{
   output_low(DAC1);
   spi_write(WRITECMD);
   spi_write(addr);
   spi_write(value);
   output_high(DAC1);
}


So... I ofcourse could put in a few IF statements or a switch, but they seem rather bloated for what they are doing, plus it would be run twice for EVERY time I called read() or write(), which I suspect will be happening a lot.

I don't know if this is a job for unions, structors, enum, etc,

Anyone have a recommended practice ?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 20, 2006 12:51 pm     Reply with quote

Look at the do_pin_io() function in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=25280
You really only need a portion of it, because you're only doing outputs.
Compile the code and look at the .LST file to see how much ASM
code it uses. Then you can decide if you want to use it, or use the
switch-case method.
iso9001



Joined: 02 Dec 2003
Posts: 262

View user's profile Send private message

PostPosted: Mon Feb 20, 2006 2:44 pm     Reply with quote

PCM in with the save..... AGAIN

I ran that example and came up with ~24 lines of code per call. With 4 if/else's I come up with a best case of 9 and a worst of 27.

For any more then 4 cases your code would work great. I'll stick with the if's for now, but I still don't like it. I'll order then ifs so that maybe I can maximize the chance of getting a best case.

I appreciate the help !
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