Chaos theory- on the oscilloscope

Hi guys. Some days ago saw this code from the forum.

I simulated it on Proteus and I was able to graph some oscillators like Lorenz, Rossler and Chua but I couldn't graph systems with 4 state equiations. I'm new in Arduino so i will really appreciate your comments

Thank you in advance.

float x_pos;         
float y_pos; 
int x_out = 5;
int y_out = 6;
float x = 0.1;
float y = 0.1;
float z = 0.1;
float w = 0.1;

float a = 3;
float b = 22;
float c = 8.1;
float d = 4.1;
 
float xdot;
float ydot;
float zdot;
float wdot;
float dt = 0.01;

void setup()  { 

  pinMode(x_out, OUTPUT);
  pinMode(y_out, OUTPUT);
  // this next section changes the PWM frequency - don't mess with it!
    TCCR0A = (  1<<COM0A1 | 0<<COM0A0 |   // clear OC0A on compare match (hi-lo PWM)
    1<<COM0B1 | 0<<COM0B0 |   // clear OC0B on compare match (hi-lo PWM)
    1<<WGM01  | 1<<WGM00);    // set PWM lines at 0xFF

  TCCR0B = (  0<<FOC0A | 0<<FOC0B |   // no force compare match
    0<<WGM02 |      // set PWM lines at 0xFF
    0<<CS02  | 0<<CS01 |    // use system clock (no divider)
    1<<CS00 );

  TIMSK0 = (  0<<OCIE0B | 0<<TOIE0 |
    0<<OCIE0A ); 
} 

void loop()  {

xdot = a*x-y*z;
ydot = -b*y+x*z-z*w;
zdot  = -c*z+x*y;
wdot = d*(y-w);

x = x + (xdot * dt);
y = y + (ydot * dt);
z = z + (zdot * dt);
w = w + (wdot * dt);  

x_pos = 128+(50 * x);
y_pos = 128+(50 * y);

analogWrite(x_out, x_pos);
analogWrite(y_out, y_pos);
}

I wonder what the italics mean.

x_out and y_out are connected to an RC circuit ?

Avoid timer 0 if you can because it is used internally by the Arduino run time system.

Something must have been graphed even if wrong, so what were the values that got sent to anslogWrite?

a7

Yes, i used a kind of kalman filter to convert the PWM signal to analog.

Thank you, i´m gonna try it.

I sent x and y variables, but when i run the simulate nothing happen, there's no voltage at the pins. :frowning:

Sorry man, they are the equations of the system.

float x_pos;         
float y_pos; 
int x_out = 5;
int y_out = 6;
float x = 0.1;
float y = 0.1;
float z = 0.1;
float w = 0.1;

float a = 3;
float b = 22;
float c = 8.1;
float d = 4.1;
 
float xdot;
float ydot;
float zdot;
float wdot;
float dt = 0.01;

void setup()  { 

  pinMode(x_out, OUTPUT);
  pinMode(y_out, OUTPUT);
  // this next section changes the PWM frequency - don't mess with it!
    TCCR0A = (  1<<COM0A1 | 0<<COM0A0 |   // clear OC0A on compare match (hi-lo PWM)
    1<<COM0B1 | 0<<COM0B0 |   // clear OC0B on compare match (hi-lo PWM)
    1<<WGM01  | 1<<WGM00);    // set PWM lines at 0xFF

  TCCR0B = (  0<<FOC0A | 0<<FOC0B |   // no force compare match
    0<<WGM02 |      // set PWM lines at 0xFF
    0<<CS02  | 0<<CS01 |    // use system clock (no divider)
    1<<CS00 );

  TIMSK0 = (  0<<OCIE0B | 0<<TOIE0 |
    0<<OCIE0A ); 
} 

void loop()  {

xdot = a*x-y*z;
ydot = -b*y+x*z-z*w;
zdot  = -c*z+x*y;
wdot = d*(y-w);

x = x + (xdot * dt);
y = y + (ydot * dt);
z = z + (zdot * dt);
w = w + (wdot * dt);  

x_pos = 128+(50 * x);
y_pos = 128+(50 * y);

analogWrite(x_out, x_pos);
analogWrite(y_out, y_pos);
}