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.

Printing wrong values proteus virtual monitor

Status
Not open for further replies.

siddu1901

Newbie level 4
Joined
Oct 13, 2021
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
50
I'm making this Electric Impedance Tomography project on proteus and the code is in arduino Mega1280. The circuit is working fine. The problem is when I'm simulating the circuit on proteus, the input voltages coming to A0 pin are being printed as 0 for some reason. Even though when I put a probe on that wire and it shows the voltage, arduino is printing as zero. Can someone help me?

Here is the code:
C:
//library of the multiplexors
#include <CD74HC4067.h>
//library for calculating RMSvalues
#include <TrueRMS.h>
// loop period time in microseconds (time between samples)
#define LPERIOD 1000
// define the used ADC input channel
#define ADC_INPUT 0


// RMS window of 40 samples, means 2 periods at 50Hz
#define RMS_WINDOW 40
unsigned long nextLoop;
int adcVal;
int cnt=0;
// ADC full scale peak-to-peak is 5.00Volts
float VoltRange = 5.00;
// create an instance
Rms readRms ;
CD74HC4067 my_mux(22,23,24,25);
CD74HC4067 my_mux2(26,27,28,29);
CD74HC4067 my_mux3(30,31,32,33);
CD74HC4067 my_mux4(34,35,36,37);
void setup()
{

pinMode(A0, INPUT);
Serial.begin(9600);
Serial.println("LABEL,v");
Serial.print("DATA, ");
readRms.begin(VoltRange, RMS_WINDOW, ADC_10BIT, BLR_ON,CNT_SCAN);
readRms.start();
// Set the loop timer variable for the next loop interval.
//micros( ) Returns the number of microseconds since the Arduino board began running the current program.


nextLoop = micros() + LPERIOD;


//electrode 0 and 1//electrode 0 and 1
my_mux.channel(0);
my_mux2.channel(1);
for (int k=2;k<15;k++)
{
my_mux3.channel(k);
my_mux4.channel(k+1);
for(int i=0;i<500;i++)
{
// Read the ADC and remove the DC-offset
adcVal = analogRead(ADC_INPUT);
//take an instance again
readRms.update(adcVal);
cnt++;
//repeating the readings of one sample
if(cnt >= 500)
{
// publish every 0.5s
readRms.publish();
Serial.print(readRms.rmsVal,2);
Serial.println();
Serial.print("DATA, ");
cnt=0;
}
// wait until the end of the time interval
while(nextLoop > micros());
// set next loop time to current time + LOOP_PERIOD
nextLoop += LPERIOD;
}
}
}
void loop(){
}

Here is the link for the proteus file:
[Moderator action: removed link to external file server]
 
Last edited by a moderator:

Hi,
Serial.print(readRms.rmsVal,2);
I think Serial.print expects a string
But readRms.rmsVal most probably is a float
--> please check both

I guess the RMS value to be not as stable as you may expect.
At least the sampling of the data.
This is because SerialPrint may be blocking and thus may take several milliseconds.
Thus during this time no analog value is converted ... but afterwards there will be multiple conversions immediately after the other.

--> the better way is to do the ADConversion interrupt driven

Klaus
 

hey Klaus!!
Thanks for the reply. Im relatively new to coding so I quite don't know how to fix the issue. I copy pasted this code from a research paper. Can you please give me a detailed explanation of how I can fix this code if possible?
This is what the arduino prints
1635586649479.png

Sid
 

Hi,

I´ve gone through the SerialPrint documentation. It seems it can work and display float variables correctly.

****

You need to learn to debug code.
Just copying code and hoping that it will work is somehow idealistic.

If you don´t get the expected ouput then try with fixed values.
***
First replace
Serial.print(readRms.rmsVal,2);
with
float testval = 1.223;
Serial.print(testval,2);

then see what happens.

***
Then replace (from your original code)
Serial.print(readRms.rmsVal,2);
with
Serial.print(adcVal);
then see what happens.

***
Show us the results

***
Btw: Why did you stop to respond to your thread in the Arduino forum? They try to help you.

Klaus
 

Hi,

I´ve gone through the SerialPrint documentation. It seems it can work and display float variables correctly.

****

You need to learn to debug code.
Just copying code and hoping that it will work is somehow idealistic.

If you don´t get the expected ouput then try with fixed values.
***
First replace
Serial.print(readRms.rmsVal,2);
with
float testval = 1.223;
Serial.print(testval,2);

then see what happens.

***
Then replace (from your original code)
Serial.print(readRms.rmsVal,2);
with
Serial.print(adcVal);
then see what happens.

***
Show us the results

***
Btw: Why did you stop to respond to your thread in the Arduino forum? They try to help you.

Klaus
Hey Klaus!
My bad I'm so new to coding so I have these troubles to debug the codes and thanks for the advice!
As you said, I replaced
Serial.print(readRms.rmsVal,2);
with
float testval = 1.223;
Serial.print(testval,2);

and this is what I got
1635590350270.png


It did printed the values but all the values are same. Even though the voltage values on the probe were varying, all the values that were printed were same

Then, I replaced
Serial.print(readRms.rmsVal,2);
with
Serial.print(adcVal);
And this is what I got
1635590562893.png

I'm assuming it printed the same values as above excluding the decimal

And yeah I'm trying to get insights from both arduino forum and here
 

Hi,

now we know:
* SerialPrint does what it is supposed to do
* the ADC reads 1023, which is the top value.

I guess the RMS calcualtes RMS excluding DC. Thus if it continously gets 1023 as input it calculates RMS as zero.

***
A new test:

add in the setup section:
int adcMin = 1024;
int adcMax = 0;


after each conversion add:
if (adcVal > adcMax)
{
adcMax = adcVal
}
if (adcVal < adcMin)
{
adcMin = adcVal
}


Then replace (from your original code)
Serial.print(readRms.rmsVal,2);
with
Serial.print(adcMin);
Serial.print(adcMax);
adcMin = 1024;
adcMax = 0;

then see what happens.

Klaus
 

Hey Klaus,
In which line do I add this part? I'm sorry to bother you so much
if (adcVal > adcMax)
{
adcMax = adcVal
}
if (adcVal < adcMin)
{
adcMin = adcVal
}
 

Hi,

This indeed was a small test whether (how much) you understand the code ... hope you don´t mind.

The conversion is done in this line: adcVal = analogRead(ADC_INPUT);
at this point the ADC converts the analog voltage at the pin ADC_INPUT and converts it to a digital value.
ADC_input is defined as 0. Which most probably means ADC Channel0.

put the code right after these line.

***
please get familiar with th code. Each line of the code. Some you may understand. Some not, then ask.

Klaus
 

Hey!
I did as you said and this is what I got
1635595731599.png


Im posting the modified code too so that you can check it and see what I did wrong

Code:
//library of the multiplexors
#include <CD74HC4067.h>
//library for calculating RMSvalues
#include <TrueRMS.h>
// loop period time in microseconds (time between samples)
#define LPERIOD 1000
// define the used ADC input channel
#define ADC_INPUT A0


// RMS window of 40 samples, means 2 periods at 50Hz
#define RMS_WINDOW 40
unsigned long nextLoop;
int adcVal;
int cnt = 0;
// ADC full scale peak-to-peak is 5.00Volts
float VoltRange = 5.00;
// create an instance
Rms readRms ;
CD74HC4067 my_mux(22, 23, 24, 25);
CD74HC4067 my_mux2(26, 27, 28, 29);
CD74HC4067 my_mux3(30, 31, 32, 33);
CD74HC4067 my_mux4(34, 35, 36, 37);
void setup()
{
  int adcMin = 1024;
  int adcMax = 0;




  Serial.begin(9600);
  Serial.println("LABEL,v");
  Serial.print("DATA, ");
  readRms.begin(VoltRange, RMS_WINDOW, ADC_10BIT, BLR_ON, CNT_SCAN);
  readRms.start();
  // Set the loop timer variable for the next loop interval.
  //micros( ) Returns the number of microseconds since the Arduino board began running the current program.


  nextLoop = micros() + LPERIOD;


  //electrode 0 and 1//electrode 0 and 1
  my_mux.channel(0);
  my_mux2.channel(1);
  for (int k = 2; k < 15; k++)
  {
    my_mux3.channel(k);
    my_mux4.channel(k + 1);
    for (int i = 0; i < 500; i++)
    {
      // Read the ADC and remove the DC-offset
      adcVal = analogRead(ADC_INPUT);
      if (adcVal > adcMax)
      {
        adcMax = adcVal;
      }
      if (adcVal < adcMin)
      {
        adcMin = adcVal;
      }
      //take an instance again
      readRms.update(adcVal);
      cnt++;
      //repeating the readings of one sample
      if (cnt >= 500)
      {
        // publish every 0.5s
        readRms.publish();
        Serial.print(adcMin);
        Serial.print(adcMax);
        adcMin = 1024;
        adcMax = 0;
        Serial.println();
        Serial.print("DATA, ");
        cnt = 0;
      }
      // wait until the end of the time interval
      while (nextLoop > micros());
      // set next loop time to current time + LOOP_PERIOD
      nextLoop += LPERIOD;
    }
  }
}
void loop() {
}
 

Hi,

so the ADC sees just too much input voltage, thus it decodes TOP level digital value.
(It never goew below 1023)

Do you have a scope?

What´s the channel 0 input voltage during program run?
What´s the ADC Reference voltage setup?
Is your ADC frequency setup correct?

Klaus
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top