View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Need a fast way of writing to multible SPI DACs |
Posted: Mon Feb 20, 2006 12:20 pm |
|
|
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
|
|
Posted: Mon Feb 20, 2006 12:51 pm |
|
|
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
|
|
Posted: Mon Feb 20, 2006 2:44 pm |
|
|
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 ! |
|
|
|