using ACS712 current sensor to read and compare values, then send pwm signal

Hello

Am having difficult figure out how to properly code my arduino uno.

am just going to briefly explain what am trying to do. i have roughly two set of data points which are current values and duty cycle that are associated with the current values below are those values:

"Current Value"
0.526
0.586
0.661
0.751
0.766
0.886
1.066
1.321
1.771
2.656

"Duty cycle"
53.5%
53.8%
54.1%
54.5%
54.6%
55.1%
55.8%
56.7%
58.3%
61.5%

for example current value .526 amps goes with duty cycle 53.5% and these 10 data point are what i will be using the acs712 current sensor to compare the values to.

now what i need help with is i need to be able to read the current every half second lets say, and compare those current values that are coming in to the 10 values that i have listed above after it finds approx the right value i want it then to send the appropate duty cycle to a specified pin on the arduino, i want this to happen continually.

Please if you could prove me with this code that will do this task or help me out that will be great, i really tried but am not able to get it going, this is what i have so far only code for sensor.

void setup() {

Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A0);
Serial.println((514sensorValue)*27.03/1023);
delay(350);
}

Thank you so much

also i forgot to mention the frequeny has to be 10 khz, this will be connected to buck converter.

Thanks

How about this, if you need to use Matlab:

writePWMDutyCycle
Generate PWM signal with specified duty cycle on digital pin

writePWMVoltage
Generate PWM signal with specified voltage on digital pin

Example:
a = arduino();
writePWMVoltage(a,'D5',3);

Your description smells like a x-y problem, you may want something (buck converter?) different from what you described. Would you give more information about your project?

In detail you should learn more about arrays and table lookup (interpolation). Also search the forum for changing the PWM frequency. For your fine grained duty cycle you may have to write your own version of analogWrite(), that allows for more than 256 duty cycle steps, using a 16 bit timer/counter.

If all that looks too complicated to you, post your project at Gigs and Collaborations for more assistance.