Hi,
I am controlling Xavier Nx’s PWM from a C++ file.
I have to occasionally turn ON/OFF the PWM waveforms and to achieve this I have implemented a function which uses basic file operations like fopen(), fprintf.
char enable_path[64] = "/sys/devices/3280000.pwm/pwm/pwmchip0/pwm0/enable";
FILE* f_en = NULL;
f_en = fopen(enable_path, "w");
if(f_en != NULL)
{
switch (state)
{
case START:
fprintf(f_en, "1");
break;
case STOP:
fprintf(f_en, "0");
break;
default:
break;
}
fclose(f_en);
}
else
{
printf("%s\n", strerror(errno));
}
This function is able to successfully turn ON/OFF the PWM for most of the times but it also fails to turn it OFF quite often. When this function fails to turn it off, I try executing following command as root user and successfully turn the PWM off,
echo 0 > /sys/devices/3280000.pwm/pwm/pwmchip0/pwm0/enable