Problem generating a exponential signal.

Hello everyone, this is my first time using this forum.

I’m trying to generate an exponential signal using the MCP4725 (one digital to analog converter, with a 12 bits resolution)
To generate the signal I’m using the next equation:
y = (x*0.5)^2
With this equation I just take the first 128 values, because in this range I get from 0 to 4096 levels corresponding to my 0 to 5V.

This is my code:

#include <Wire.h>
#include <Adafruit_MCP4725.h>

Adafruit_MCP4725 dac;

uint16_t datos[128];
int i;
int y;

void setup() {
dac.begin(0x60);
Serial.begin(9600);

for(i = 1; i < 129; i++)
{
y = pow((i*0.5),2);
datos *= y; *

  • }*
    }
    void loop() {
  • for(int j = 0; j < 128; j++)*
  • {*
  • dac.setVoltage(pgm_read_word(&(datos[j])), false);*
  • Serial.println(datos[j]);*
  • }*
    }
    I have the equation inside of a “for” to get the values of the equation and then I save those values in the array.
    The problem then, is when I take those values from the array and send them. I plot the values with arduino and i got this: (First image)
    But then in the oscilloscope I have this: (Second Image)
    Does someone have an idea of what could be the problem or how could I solve it?

for(i = 1; i < 129; i++)Oops.

Please remember to use code tags when posting code

The equation:
y = (x*0.5)^2
factors to
y = x * x / 4

That will be a lot more efficient since in your program, x and y are both integers.

Thanks, I'll read the rules to post, and I'll try with the new equation.

daniro_118:
Thanks, I'll read the rules to post, and I'll try with the new equation.

Use long int for that, the x*x could overflow a 16 bit int.

your not saving the values

    datos [i] = y;

and check the start and end values of all your loops

#define N   128
uint16_t datos[N];

    for(i = 0; i < N; i++)

Please don't cross post threads.
Problemas generando una señal exponencial

Next time you'll be banned.