You need to log in to create posts and topics.

Is there a way to see the value of a variable?

Hello everyone, I have designed a digital filter in Arduino (328p) and I would like to see the value of some variables that make up the filter. Using the function to view the processor registers I can see the ADCH and ADCL, as well as other registers. When I run the simulation I can see some variables, but not all, although I define them in the same way in the code. If I do this (very summarized):
y0=5*x1+3*x2-8*y1
x2=x1
y1=y0
I can see the values ​​that x1, x2, y1 take. But I can't see the value of y0.
Is there any way to define the variables so I can see them in simulation?
Greetings.

Hi.

The compiler often optimizes variables out.
In this case y1=y0, so most probably the compiler thinks  that it doesn't make any sense to keep 2 variables for the sane value.

Hello Mr. Arcachofo this is the code for 328p. It is a digital low pass filter, if you run it with an frecuency input in A0 (2vpek DC level 2.5v) and atach an DAC in  portD you can see from 0hz to 500hz the output level is the same, but over 500hz the level falls until 0 (more or less):

float b0 = 0.02995247960866337400;

float b1 = 0.05990495921732674800;

float b2 = 0.02995247960866337400;

float a1 = -1.45424358625158500000;

float a2 = 0.57406191508395477000;

int n = 0 ;

int d = 0 ;

int x0 = 0;

int x1 = 0;

int x2 = 0;

int y1 = 0;

int y2 = 0;

int y0 = 0;

void setup() {

DDRD =0b11111111;

DDRB =0xff;

}

void loop() {

x0 = analogRead(A0);//-512;

y0 = (b0 * x0 + b1 * x1 + b2 * x2)-(a1 * y1 + a2 * y2);

x2 = x1;

x1 = x0;

y2 = y1;

y1 = y0;

PORTD = y0>>2 ;

PINB=0x1;

}

if open mcu monitor when run the code, only wil see x1, x2, y1, y2, if you change the type to int32_t the value do no apear (maybe a bug). the question It is any way  to see the value of y0 and x0? I can eee it in the ram, but it is not a good way.

Thank you for your time

Pablo.

Hi ea2ehc.

If a variable does not appear in Mcu Monitor is because is not global or has been optimized.

You can try to declare it as "volatile" but the compiler can ignore it.
Also to use it in another function. For example move this to a function: y0 = (b0 * x0 + b1 * x1 + b2 * x2)-(a1 * y1 + a2 * y2);