Using 3 MCP9xx1 ( DAC)

Hello!!

I am going to need three different analog output for my arduino nano.
I started my project with one and I had to my output a DAC MCP9xx1.
Non my question is, how I manege the SPI libriary for three different output?

I don't unserdand how it will devide the works between the three DAC.

How I hqve to configure the three SS?
For one I am using pin 10 of arduino, I am using ping 13 for the clock, and pin 11 for the MOSI communication.
the signal that currently is going Inside the DAC is a PWM

TCCR2A |= (1 << WGM20);

  bitClear(TCCR2B, CS20); //set prescaler to 8
  bitSet(TCCR2B, CS21);
  bitClear(TCCR2B, CS22);

and the SPI clock divider is

 dac.setSPIDivider(SPI_CLOCK_DIV128);

I am not using latch pin on ground.

the other two signal will be coming out from pin 5 and 6, so TIMER1, they will have different frequency.

So I have question in how to configure the Library SPI,
Do I need to use latch and what is its use?

Giulialiuyi:
Hello!!

I am going to need three different analog output for my arduino nano.
I started my project with one and I had to my output a DAC MCP9xx1.
Non my question is, how I manege the SPI libriary for three different output?

what is the actual part number of your DAC? Searching for a MCP9xx1 does not result in any hits.

Most of MicroChips DAC's are MCP47xx - MCP49xx part numbers?

The answer requires a fuller question. (need more data)

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

what is the actual part number of your DAC?

I wrote wrongs nulber!!!! It is MCP4901 a 8 bit DAC
here the data sheet:

I want to use separately the three DAC. Before one then the second one finaly the third one. But, I have problem already in the connection I think.

I made the definition for three different SS.

#include <SPI.h>         //
#include <DAC_MCP49x1.h>
#define SS1 10 //Slave Select Chip 1
#define SS2 9  //Slave Select Chip 2
#define SS3 8  //Slave Select Chip 3
DAC_MCP49x1 dac(DAC_MCP49x1::MCP4901, SS1);
DAC_MCP49x1 dac1(DAC_MCP49x1::MCP4901, SS2);
DAC_MCP49x1 dac2(DAC_MCP49x1::MCP4901, SS3);

in the void setup() {}

 pinMode(SS1, OUTPUT); // portabB
  pinMode(SS2, OUTPUT);
  pinMode(SS3, OUTPUT);
 
  dac.setSPIDivider(SPI_CLOCK_DIV8);
  //dac.setPortWrite(false);
  dac1.setSPIDivider(SPI_CLOCK_DIV128);
  //  dac1.setPortWrite(false);
  dac2.setSPIDivider(SPI_CLOCK_DIV128);
  //  dac2.setPortWrite(false);

and then in void loop I run this function: int rx() {}
whos definition is:

int RX()
{
  if (digitalRead(A4) == LOW)// lettura valore codice
  {
    for (int offset = 0; offset ++; offset < 5)
    {
      val = digitalRead(A4) << offset; //variabile scorrimento IDCODE
    }
    return val;

   switch (val)
   {
     case 001:
    if (val = 0,0,0,1)
    voltage = ((pulseIn(A5, LOW, 1280) * 100) / 128) >> 1;
    voltage = map(constrain(voltage, 0, 100), 0, 100, 0, 255);//statement
    dac.output(voltage);
         break;

        case 010:
          voltage1 = ((pulseIn(A5, LOW, 1280) * 100) / 128) >> 1;
          voltage1 = map(constrain(voltage1, 0, 100), 0, 100, 0, 255);
        dac2.output(voltage1);
          break;
  
        case 011:
          voltage2 = ((pulseIn(A5, LOW, 1280) * 100) / 128) >> 1;
          voltage2 = map(constrain(voltage2, 0, 100), 0, 100, 0, 255);
          dac3.output(voltage2);
            break;

      }
  }
}

Giulialiuyi:
I wrote wrongs nulber!!!! It is MCP4901 a 8 bit DAC
here the data sheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/22248a.pdf

I've added some comments to your code.
Is this actually 'compiling' code?

int RX()
{
  if (digitalRead(A4) == LOW)// lettura valore codice
  {
    for (int offset = 0; offset ++; offset < 5)
		**********************  This for loop is invalid
	// as you have written it, offset is set to zero, the loop terminates when offset is zero, and offset <5 is how the loop variable increments?
    {
      val = digitalRead(A4) << offset; //variabile scorrimento IDCODE
    }
    return val;
****************************** return will exit, anything past this line will never execute.
   switch (val) 
   {
     case 001:
    if (val = 0,0,0,1) // what are you trying to do here? 
       // if i interpret it correctly val becomes 1 and is always evaluated as true?

    voltage = ((pulseIn(A5, LOW, 1280) * 100) / 128) >> 1;
    voltage = map(constrain(voltage, 0, 100), 0, 100, 0, 255);//statement
    dac.output(voltage);
         break;

        case 010:
          voltage1 = ((pulseIn(A5, LOW, 1280) * 100) / 128) >> 1;
          voltage1 = map(constrain(voltage1, 0, 100), 0, 100, 0, 255);
        dac2.output(voltage1);
          break;
  
        case 011:
          voltage2 = ((pulseIn(A5, LOW, 1280) * 100) / 128) >> 1;
          voltage2 = map(constrain(voltage2, 0, 100), 0, 100, 0, 255);
          dac3.output(voltage2);
            break;

      }
  }
}

Chuck.

Thank you a lot for your comments chuck! I really need advice in programmation.
What I was thinking to do there it was a kind of identification.
Since I am sending three different signal I would like to send to the receiver first a sort of password that tells him which signal is which.
I have no idea how can I do that.