Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Sawtooth waveform on arduino

Status
Not open for further replies.

Chinmaye

Full Member level 3
Joined
Jan 18, 2016
Messages
164
Helped
0
Reputation
0
Reaction score
1
Trophy points
1,298
Activity points
3,145
Hello,
I am trying to generate a sawtooth waveform using Arduino and DAC 0808. I connected the two checked that the DAC works properly. That is when i make MSB = 1 and rest of the bits =0, Multimeter reads vref/2. I have configured pins 2 to 9 are output pins with 2 being LSB and 9 MSB. I also see that it works fine on serial monitor. Not sure whats wrong with it. Please help.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
int val;
byte mask;
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
for (int i = 2; i < 10; i++)
  {
    pinMode(i, OUTPUT);
  }
  val = 0;
}
 
void loop() {
  // put your main code here, to run repeatedly:
 
 
   int k =2;
   for (mask = 00000001; mask>0; mask <<= 1) { //iterate through bit mask
    if (val & mask){ // if bitwise AND resolves to true
      digitalWrite(k,HIGH); // send 1
   
    }
    else{ //if bitwise and resolves to false
     digitalWrite(k,LOW); // send 0
 
}
   k++;
   }
 
val++;
if (val > 255)
 
  val = 0;
 
}

 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top