Chua chaotic oscillator and MCP4922 DAC

Dependencies:   mbed

Committer:
JLS
Date:
Sat May 07 19:27:14 2011 +0000
Revision:
0:e5edc0373da0

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JLS 0:e5edc0373da0 1 #include "mbed.h"
JLS 0:e5edc0373da0 2 #include "MCP4922.h"
JLS 0:e5edc0373da0 3
JLS 0:e5edc0373da0 4 MCP4922 MCP(p5, p7,p8); // MOSI, SCLK, CS
JLS 0:e5edc0373da0 5
JLS 0:e5edc0373da0 6 int main() {
JLS 0:e5edc0373da0 7
JLS 0:e5edc0373da0 8 MCP.frequency(1000000);
JLS 0:e5edc0373da0 9
JLS 0:e5edc0373da0 10 float x = 0.5;
JLS 0:e5edc0373da0 11 float y = 0.25;
JLS 0:e5edc0373da0 12 float z = 0.125;
JLS 0:e5edc0373da0 13 float oldx = 0;
JLS 0:e5edc0373da0 14 float oldy = 0;
JLS 0:e5edc0373da0 15 float oldz = 0;
JLS 0:e5edc0373da0 16
JLS 0:e5edc0373da0 17 float dt = 0.005;
JLS 0:e5edc0373da0 18
JLS 0:e5edc0373da0 19 float alpha = 15.6;
JLS 0:e5edc0373da0 20 float beta = 28.58;
JLS 0:e5edc0373da0 21 float a = -1.14286;
JLS 0:e5edc0373da0 22 float b = -0.714286;
JLS 0:e5edc0373da0 23 float h = 0;
JLS 0:e5edc0373da0 24
JLS 0:e5edc0373da0 25 int xout = 0;
JLS 0:e5edc0373da0 26 int yout = 0;
JLS 0:e5edc0373da0 27
JLS 0:e5edc0373da0 28 while (1) {
JLS 0:e5edc0373da0 29
JLS 0:e5edc0373da0 30 oldx = x;
JLS 0:e5edc0373da0 31 oldy = y;
JLS 0:e5edc0373da0 32 oldz = z;
JLS 0:e5edc0373da0 33
JLS 0:e5edc0373da0 34 h = (b * x) + (0.5 * (a - b) * (abs(x+1) - abs(x-1)));
JLS 0:e5edc0373da0 35
JLS 0:e5edc0373da0 36 x = oldx + dt * (alpha * (oldy - oldx - h));
JLS 0:e5edc0373da0 37 y = oldy + dt * (oldx - oldy + oldz);
JLS 0:e5edc0373da0 38 z = oldz + dt * (-beta * oldy);
JLS 0:e5edc0373da0 39
JLS 0:e5edc0373da0 40 xout = 2047+(850*x);
JLS 0:e5edc0373da0 41 yout = 2047+6*(800*y);
JLS 0:e5edc0373da0 42
JLS 0:e5edc0373da0 43 MCP.writeA(xout);
JLS 0:e5edc0373da0 44 MCP.writeB(yout);
JLS 0:e5edc0373da0 45
JLS 0:e5edc0373da0 46 }
JLS 0:e5edc0373da0 47 }