1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

DAC0832 simulating with Proteus and Arduino

Discussion in 'Circuit Simulation & PCB Design' started by pabspagg, Mar 2, 2017.

  1. pabspagg

    pabspagg New Member

    Joined:
    Mar 2, 2017
    Messages:
    4
    Likes:
    0
    Hi,
    I am doing a project for an electronic class I am taking.
    What I have to do is : Using an arduino as a counter ( 8 bits Counter) connected to a DAC0832 and in the output generating a Sine wave ( I can't use arduino for generating the sine wave. I will use amp ops later ). The last part I haven't simulate yet.
    Cicuito Proteus com simulação.PNG

    The problem is the following: I want the wave output to be triangular at first, with steps ups and downs . But now I am only getting the steps going down ( I am using an AMP OP inverter) and it's not going up ( Why not? ) . As you can see in the image, the arduino code is working 100%. It's going from 0 to 255 then 255-0. ( I am only showing part of it).

    ArduinoContagem.PNG

    Thanks a lot!
    Sorry for the bad english :)
     
  2. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi p,
    Look at this clip from the datasheet, the Vout polarity is negative.
    E
    A002.gif
     
    • Like Like x 1
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi p,
    Try to simulate this version of the circuit taken from the datasheet.
    E
    A003.gif
     
    • Like Like x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. pabspagg

    pabspagg New Member

    Joined:
    Mar 2, 2017
    Messages:
    4
    Likes:
    0

    Thanks for the answer.

    I just did . See what I got :
    newcircuit.PNG

    I am not sure if I was clear about what I want. The wave in the end should be like this ( With small steps increasing and decreasing ) . Do you know how can I fix ?: wave.jpg
     
  6. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,189
    Likes:
    644
    Location:
    Ex Yorks' Hants UK
    hi p,
    If you post your program listing I am sure one of us could help.
    Looking at your print out, you seem to be incrementing the DAC input, in one bit steps, the input inc/dec should follow a Sine wave sequence.
    E
     
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    Can you post the code.... The simulation shows a ramp output... Its the code you need to change.. you have decreasing amounts going to the DAC but then when it hits bottom you need to slowly increase not start all over!!
     
  8. pabspagg

    pabspagg New Member

    Joined:
    Mar 2, 2017
    Messages:
    4
    Likes:
    0
    Sure , here's the code :
    Code (c):

    void setup() {
     
       DDRD = 255;
    }

    void loop() {
     
      PORTD++;
      delay(100);
      if ( PORTD == 255){
        while ( PORTD != 0 ){
          PORTD--;
          delay(100);
          }
      }
    }
     
    // I'm using Port manipulation in arduino. https://www.arduino.cc/en/Reference/PortManipulation
    Maybe that's the problem?
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    When portd-- != 0.... It'll mess up with this...

    The easier way is an index

    Code (c):

    int inc = 1;
    void setup() {
       PORTD = 0;
       DDRD = 255;
    }

    void loop()
       {
        PORTD += inc;
        delay(100);
         if ( PORTD > 254 ) inc = -1;
         if ( PORTD < 1 ) inc = 1;
        }
     
     
    Last edited: Mar 4, 2017
    • Like Like x 2
  10. pabspagg

    pabspagg New Member

    Joined:
    Mar 2, 2017
    Messages:
    4
    Likes:
    0
    After trying a lot to solve the problem. The issue was indeed the code. It turned out that it wasn't a viable option using PORT manipulation on arduino .
    Here's the new one .
    Code (text):

    int led[8] = {0,1,2,3,4,5,6,7};
    boolean A[8];
    int inc=1;
    int saida=0;

    void setup() {  
      for(int i=0;i<8;i++)  {  
        pinMode(led[i], OUTPUT);  
      }  
    }

    void loop() {  
      saida += inc;  
      if( saida > 254 )  {  
          inc= -1;  
        }  
      if( saida < 1 )  {  
          inc= 1;  
        }  
      conversor();  
     
      for(int i=0;i<8;i++)  {  
        digitalWrite(led[i],A[i]);  
      }  
    }
    void conversor(){
      int valor=saida;
      for(int i=0;i<8;i++)  {
          if(valor%2>0)    {
              A[i]=1;
            }
            else    {
              A[i]=0;
            }
          valor=(valor/2);
        }
      }
     
    The output I am getting now. There's some noise. I'm still trying to figure out how to remove this.

    new.PNG
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,170
    Likes:
    910
    Location:
    Rochdale UK
    The noise isn't software... This is because you dac is seeing the transition for level to level... The ouput buffer should be clocked only when the new data has been shifted in...
     

Share This Page