I am trying to control frequency and duty cycle through c-program based on wiringPi library.
Here is the code:
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main (void)
{
printf ("Raspberry Pi wiringPi test program\n") ;
if (wiringPiSetupGpio() == -1)
exit (1) ;
pinMode(1,PWM_OUTPUT);
pwmSetMode(PWM_MODE_MS);
pwmSetClock(1920);
pwmSetRange (10) ;
pwmWrite (1, 30);
}
When I execute it by:
sudo gcc -Wall -o sh pwm.c -lwiringPi
sudo chmod 777 sh
./sh
I see on my oscilloscope just single impulse when I run my program and then nothing, dead silence.. nothing like pwm and LED is just lighting
I cannot explain it.. I understand it this way. When I execute my program, pin number 12 (number 1 according to wiringPi library) must be configurated to some frequency and duty call and stands the same till the moment when I change some parameters in my code and run this program again.. but this behavior I cannot explain, especially when commands on bash like:
gpio mode 1 pwm
gpio pwm-ms
gpio pwmr 200
gpio pwm 1 30
gpio pwmc 1920 # and then I modified pwmc and see frequency being changed as it should be!
when I change gpio pwmc 2000 to gpio pwmc 40 and gpio pwmc 4000 I see pwm on my oscilloscope and see my LED blinking...
What is wrong with my understanding, why it is working okay on bash and does not appropriate work on C? How whould I change my code on C to achieve the same ?
Thank you