Chinmaye
Full Member level 3
Hello Experts,
Aa an exercise, I am trying to interface 10 bit ADC MCP3008 wit Arduino-UNO. I am giving a Sine wave input to ADC. I am trying to pass the output of ADC to the DAC and View the same sine wave on the CRO. Sine ADC is 10 Bit and DAC 8 bit, I am trying to Remove the last two bits from the ADC output before giving it to the DAC. Attached is the code. I have also attached the comparison of the original waveform (Green) and the output that i am getting. I am not able to make out what the mistake is ?
Aa an exercise, I am trying to interface 10 bit ADC MCP3008 wit Arduino-UNO. I am giving a Sine wave input to ADC. I am trying to pass the output of ADC to the DAC and View the same sine wave on the CRO. Sine ADC is 10 Bit and DAC 8 bit, I am trying to Remove the last two bits from the ADC output before giving it to the DAC. Attached is the code. I have also attached the comparison of the original waveform (Green) and the output that i am getting. I am not able to make out what the mistake is ?
Code:
#include <MCP3008.h>
#include <SPI.h>
#define CS_PIN 10
#define CLOCK_PIN 13
#define MOSI_PIN 11
#define MISO_PIN 12
int pins[] = {2, 3, 4, 5, 6, 7, 8, 9};
byte mask;
// put pins inside MCP3008 constructor
MCP3008 adc(CLOCK_PIN, MOSI_PIN, MISO_PIN, CS_PIN);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
for (int i = 2; i < 10; i++)
{
pinMode(i, OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
int val = adc.readADC(0);
Serial.println(val);
//delay (500);
int k =0;
for (mask = 0000000001; mask>0; mask <<= 1) { //iterate through bit mask
if (k>1){
if (val & mask){ // if bitwise AND resolves to true
digitalWrite(k,HIGH); // send 1
// Serial.print("1");
//Serial.println(k);
//delay (200);
}
else{ //if bitwise and resolves to false
digitalWrite(k,LOW); // send 0
//Serial.print("0");
//Serial.println(k);
//delay (200);
}
}
k++;
}
}