Sinusoidal PWM signal for controlling H-bridge

Hello,

I want to make a small steeringrobot with a DC motor connected to arduino which let’s the steering wheel turn with a sinusoidal movement with a pre-defined frequency.
I already tried with the build in sin() function of arduino but it seems like I can’t choose any step/frequency lower than 1?
I also saw on several forums that the most people use sin tables, but what is the difference between the sin tables and the sin() function of arduino?

This is the code I already have:

int MotorLinks=5;
int MotorRechts=6;
int frequency=1; //In Hz
int K=1; //Correctiefactor (P-regeling)
const float pi = 3.14;
float sinfunction=0;
int x=0;


void setup() {
  pinMode(MotorLinks, OUTPUT);
  pinMode(MotorRechts, OUTPUT);
  Serial.begin(9600); 

}

void loop() {
int frequency_realtime=frequency*K;
Serial.println(frequency_realtime);
for(x=0;x<50*pi;x++){
sinfunction=255*sin(x*frequency_realtime);
Serial.println(sinfunction);
delay(150);
if(sinfunction<=0){
sinfunction=-sinfunction;
analogWrite(MotorLinks,0);
}else{
analogWrite(MotorRechts,0);
}

}

}

You haven't indented your code very well!

You use 0 in the analogWrite calls, not sinfunction.

A table of sine values is about 5000 times faster as there is no floating point hardware on (most)
Arduinos.

Perhaps you meant to write both analog pins:

void loop()
{
  int frequency_realtime = frequency*K ;
  Serial.println(frequency_realtime);
  for (int x = 0 ; x < 50 * M_PI ; x++)   // x shouldn't be global, M_PI is the built-in constant for pi
  {
    float sinfunction = 255 * sin (x*frequency_realtime);
    Serial.println(sinfunction);
    delay(150);
    if (sinfunction <= 0)
    {
      analogWrite (MotorLinks, 0) ;           // cancel any drive from last time
      analogWrite (MotorRechts, -sinfunction) ;
    }
    else
    {
      analogWrite (MotorRechts, 0) ;           // cancel any drive from last time
      analogWrite (MotorLinks, sinfunction) ;
    }
  }
}