# 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>

uint16_t datos;
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; *

` 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.

``````    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++)
``````