ARDUINO COMMUNICATION WITH 4 DEVICES

I WANT TO USE ARDUINO AND COMMUNICATE WITH 4 DEVICES:
DDS AD9835
DIGIPOT AD5204
TWO DAC08
I AM USING LABVIEW VISA WRITE FUNCTIONS AND PASSING HEX STRINGS TO ARDUINO
FOR PROG IN ARDUINO THESE HEX STRINGS ARE CONVERTED TO INTEGER USING htoi file which i have created.
then it stored in a variable and actions are to be performed.
upon reception of hex strings from labview proper actions must bee taken
but noting happens
and plus if anythin is passed through serial monitor there r no changes
my mega 2560 is good n so is my hardware
whats wrong i m not able to see..
can somebody help??
this is really urgent

#include <SPI.h> // to begin serial communication with digipot
#include <AD9835.h>// a libray found from net for DDS AD 9835 to generate sinewaves of desired frequencies.
#include "htoi.h" // created in order to to convert the hex strings into int from 00 to 255 these hex codes are recvd from labview visa functio and are user selectable


int frequency[11] = {
  125,250,500,750,1000,1500,2000,3000,4000,6000,8000}; // these are the set of frequencies which DDS will generate upon selection from labview
int noiseintensity[8] = {
  0,31,63,95,127,161,192,223}; //codes for 1st DAC08 user selectable from labview
int toneintensity[8] = {
  0,31,63,95,127,161,192,223}; //codes for 2nd DAC08 user selectable from labview
/*pin 8 = direct connection
 pin 9 = 40dB attenuation
 pin 10 = 80dB attenuation for noise*/  // at 8,9,10 relays are attached. amongst these any one will be selected from labview selection is performed
int noiserelay[3] = {
  8,9,10};
/*pin 11 = direct connection
 pin 12 = 40dB attenuation
 pin 13 = 80dB attenuation for tone*/ //at 11,12,13 relays are attached. amongst these any one will be selected from labview selection is performed
int tonerelay[3] = {
  11,12,13};
/*pin 14 = Tone Right relay
 pin 15 = Noise Right relay
 pin 16 = Tone left relay
 pin 17 = Noise left relay*/at14,15,16,17  relays are attached. amongst these any one will be selected from labview selection is performed
int righttone = 14;
int rightnoise = 15;
int lefttone = 16;
int leftnoise = 17;
int a;

AD9835 dds(
7, // FSYNC
3, // SCLK
2, // SDATA
6, // FSEL
5, // PSEL1
4, // PSEL0
50000000 // hzMasterClockFrequency (50MHz)
);
int z = 0;
void setup()
{
  for(int x = 0; x<3; x++)
  {
    pinMode(tonerelay[x], OUTPUT);
    pinMode(noiserelay[x], OUTPUT); 
  }
  pinMode(righttone, OUTPUT);
  pinMode(rightnoise, OUTPUT);
  pinMode(lefttone, OUTPUT);
  pinMode(leftnoise, OUTPUT);
  DDRC = 0xff; //tone DAC pins
  DDRA = 0xff; //noise DAC pins
  Serial.begin(9600);
  dds.begin();
 
}

void loop()
{
  char mystring[4];
  while(Serial.available())
  {
    char check = Serial.read();
    if(check == 'K')
    {
      {
        Serial.print("Ready");
        while(Serial.available())
        {
          for(int i = 0;i<4; i++)
          {
            mystring[i] = Serial.read();
            delay(50);
            // delay to avoid overwrite previous value
          }
          if(mystring[0]== '*' && mystring[3]== '#')
          {
            a = htoi(mystring[1], mystring[2]);
            compare(a);
          }
          //this loop checks wheather data only between two special chaarcters is recvd and garbage is not recvd
        }
      }
    }
  }
}

void compare(int a) // this function upon reception of data. frequency codes are between 20 and 30 and so on as explained so different functions are created.
{
  if(a >= 20 && a <=30)
  {
    freq(a);
  }
  else if(a >= 40 && a <= 64)
  {
    tone_intensity(a);
  }
  else if(a >= 70 && a <= 94)
  {
    noise_intensity(a);
  }
  else if(a >= 100 && a <= 102)
  {
    noiseselect(a);
  }
  else if(a >= 103 && a <= 105)
  {
    toneselect(a);
  }
}
// these conditions of relay selection are correct but at the pins the hih signals are not seen. 0v is seen instead of 5v.
void freq(int a)
{
  a = a-20; // this is done so that frequncy is selected from array declared in beginning amongst 11 frequncies and further codes are from library dds ad9835.
  dds.setFrequencyHz(0, frequency[a]);
  dds.selectFrequencyRegister(0);

  // Without modulation the choice of phase offset does not matter,
  // but we set it to zero for good measure.
  dds.setPhaseDeg(0,0);
  dds.selectPhaseRegister(0);

  // Finally, we turn on the IC.
  dds.enable();
}

/*tonerelay[0]: pin 11 = direct connection
 tonerelay[1]: pin 12 = 40dB attenuation
 tonerelay[2]: pin 13 = 80dB attenuation for tone*/
void tone_intensity(int a)
{
  a = a-40; // this is done to seelct the element from array of DAC codes declared earlier
  if(a >= 0 && a <= 7)
  {
    digitalWrite(tonerelay[0], 0);
    digitalWrite(tonerelay[1], 0);
    digitalWrite(tonerelay[2], 1);
    PORTC = toneintensity[a];
  }
  else if(a >= 8 && a <= 15)
  {
    digitalWrite(tonerelay[0], 0);
    digitalWrite(tonerelay[2], 0);
    digitalWrite(tonerelay[1], 1);
    a = a - 8;
    PORTC = toneintensity[a];
  }
  else if(a >= 16 && a <= 24)
  {
    digitalWrite(tonerelay[1], 0);
    digitalWrite(tonerelay[2], 0);
    digitalWrite(tonerelay[0], 1);
    a = a - 16;
    PORTC = toneintensity[a];
  }
}

/*noiserelay[0]: pin 8 = direct connection
 noiserelay[1]: pin 9 = 40dB attenuation
 noiserelay[2]: pin 10 = 80dB attenuation for noise*/
void noise_intensity(int a)
{
  a = a- 70;
  if(a >= 0 && a <= 7)
  {
    digitalWrite(noiserelay[0], 0);
    digitalWrite(noiserelay[1], 0);
    digitalWrite(noiserelay[2], 1);
    PORTA = noiseintensity[a];
  }
  else if(a >= 8 && a <= 15)
  {
    digitalWrite(noiserelay[0], 0);
    digitalWrite(noiserelay[2], 0);
    digitalWrite(noiserelay[1], 1);
    a = a - 8;
    PORTA = noiseintensity[a];
  }
  else if(a >= 16 && a <= 24)
  {
    digitalWrite(noiserelay[2], 0);
    digitalWrite(noiserelay[1], 0);
    digitalWrite(noiserelay[0], 1);
    a = a-16;
    PORTA = noiseintensity[a];
  }
}

/*pin 14 = Tone Right relay: righttone
 pin 15 = Noise Right relay: rightnoise
 pin 16 = Tone left relay: lefttone
 pin 17 = Noise left relay: leftnoise*/
void noiseselect(int a)
{
  if (a == 100)
  {
    digitalWrite(rightnoise, LOW);
    digitalWrite(leftnoise, LOW);
  }
  else if(a == 101)
  {
    digitalWrite(leftnoise, LOW);
    digitalWrite(rightnoise, HIGH);
  }
  else if(a == 102)
  {
    digitalWrite(rightnoise, LOW);
    digitalWrite(leftnoise, HIGH);
  }
}

void toneselect(int a)
{
  if (a == 103)
  {
    digitalWrite(righttone, LOW);
    digitalWrite(lefttone, LOW);
  }
  else if(a == 104 && rightnoise == 0)
  {
    digitalWrite(lefttone, LOW);
    digitalWrite(righttone, HIGH);
    delay(1000);
    digitalWrite(righttone, LOW);
  }
  else if(a == 105 && leftnoise == 0)
  {
    digitalWrite(righttone, LOW);
    digitalWrite(lefttone, HIGH);
    delay(1000);
    digitalWrite(lefttone, LOW);
  }// these relay selections logic is correct but it doeno make the pins of aruino high.
}

//THE HTOI FILE IS: // the file which converts the recvd hex string into int since char cant be compared int can be.this is e.g.(164= 160+4) like wise FF=255= 240+15 as per this code and likewise.
int ten(char tens)
{
  switch(tens)
  {
    case '0':
    return 0;
    case '1':
    return 16;
    case '2':
    return 32;
    case '3':
    return 48;
    case '4':
    return 64;
    case '5':
    return 80;
    case '6':
    return 96;
    case '7':
    return 112;
    case '8':
    return 128;
    case '9':
    return 134;
    case 'A':
    return 160;
    case 'B':
    return 176;
    case 'C':
    return 192;
    case 'D':
    return 208;
    case 'E':
    return 224;
    case 'F':
    return 240;
    
  }
}

int unit(char units)
{
  switch(units)
  {
    case '0':
    return 0;
    case '1':
    return 1;
    case '2':
    return 2;
    case '3':
    return 3;
    case '4':
    return 4;
    case '5':
    return 5;
    case '6':
    return 6;
    case '7':
    return 7;
    case '8':
    return 8;
    case '9':
    return 9;
    case 'A':
    return 10;
    case 'B':
    return 11;
    case 'C':
    return 12;
    case 'D':
    return 13;
    case 'E':
    return 14;
    case 'F':
    return 15;
  }
}

int htoi(char tens, char units)
{
  int a = ten(tens);
  int b = unit(units);
  int sum = a + b;
  return sum; // return sum because that is the actual final code.
}

MY DIGIPOT PROG IS NOT YET ADDED. THAT I WILL DO ONCE THIS SOLVED.

regards
vanashree

this is really urgent

In that case why not read the posting guidelines and make it easier for people to help you.

Don't expect others to share your urgency - that is not fair.

Computer problems rarely get easier when they become urgent.

My guess is that you need to write a short sketch to test out and learn how to do the pieces that don't work rather than try to solve the problem in a large sketch that contains lots of other stuff.

...R

I mean i didnt realize my caps is "on". m sorry...u said me to edit my post n add some tqgs?? or tags??
now i have attached my prog file.ino
kindly go through it
i m doing a project where i am trying to develop an Audiometer.
i have already connected each part individually but things work individually.together there is some prob. is something missing in this prog??
sorry for caps in earlier post

dds13th_feb.ino (5.04 KB)

dds13th_feb.ino (5.04 KB)

i expect ports going high +5v on reception of codes but they remain 0volts...
i mean i dont get the signals on the pins at all. but individually it works.i get proper signals.

can anybody telll me what is wrong or missing in my code?

vanashree:
can anybody telll me what is wrong or missing in my code?

You have a lot of code and you have not provided any explanation of what the different parts are supposed to do or how they do it. I'm not willing to spend all the time it would take to work all that out for myself.

If you explain how your code is intended to work I will have another look at it.

Is the code in the attachment the same as in your original post? It would still be helpful if you modify your original post to put the code between code tags (the # button) so it looks like this.

...R

i did that # code stuuff and also have made comments at almost every place necessary.
this is an attempt to make audiometer device which has lot of hardware i.e. noise generation circuit sine wave genertaor and and there selecctions from relays.the amplitude of sine wave n noise signals is handled using DAC. it is an attempt to mkw stuff digital using arduino.and user freiendly using labview which provides beautiful front panel environment (like in vb).now when i run prog individually all the devices run but in this when they are grouped it doesnt. an i get 0v at all pins on all inputs.
NOW,

my question is is there a way whwere i can icheck what value my variable has?i mean i am transmitting code but is it recvng??

Thank you for putting your code into code tags.

May I use this as an example of your comments - it seems fairly typical.

// Without modulation the choice of phase offset does not matter,
  // but we set it to zero for good measure.

If I knew what modulation was about I might understand the comment.

As far as I can see your comments explain small details which are probably very useful reminders for you. However they don't tell me anything about what the code is trying to achieve or how it is trying to do it.

Can you write a plain language (i.e. not computer code) description of what each function is for and how it is supposed to work.

If you had a problem with a short piece of code - say 10 or 20 lines - I would probably be able to figure it out myself. But it would take me a few hours to figure all your stuff out.

...R