-
Notifications
You must be signed in to change notification settings - Fork 6
PWM API
#PWM API
This page contains native API functions for accessing PWMs of beaglebone black. Code of this API can be found in pwm.c. Sample JNI wrapper functions can be found here. Sample application for PWM can be found here
###PWM API functions description
- int pwmSetPeriod(const uint8_t channel, const uint32_t period_ns) : It takes channel and period to be assigned in nano seconds and sets period of that channel to specified value using file system. If pwmSetPeriod() is successful then 0 is returned otherwise -1 is returned.
Returns : 0 on success and -1 if it fails.
Example :
int period = 1000000 ;
int ret = pwmSetPeriod(0, period); // It sets period for channel 0;
- int pwmGetPeriod(const uint8_t channel) : It takes channel number as input and returns the value of period of specified channel in nano seconds.
Returns : value of period on success and -1 if it fails.
Example :
int period = pwmGetPeriod(0); // It returns period for channel 0.
- int pwmSetDutyCycle(const uint8_t channel, const uint32_t duration_ns) : It takes channel and duty cycle to be assigned in nano seconds and sets duty cycle of that channel to specified value using file system. If pwmSetDutyCycle() is successful then 0 is returned otherwise -1 is returned.
Returns : 0 on success and -1 if it fails.
Example :
int dutycyle = 500000;
int ret = pwmSetDutyCycle(0, dutycycle); // It sets duty cycle for channel 0.
- int pwmGetDutyCycle(const uint8_t channel) : It takes channel number as input and returns the value of duty cycle of specified channel in nano seconds.
Returns : value of duty cycle on success and -1 if it fails.
Example :
int dutycycle = pwmGetDutyCycle(0); // It returns duty cycle for channel 0.
- int pwmSetPolarity(const uint8_t channel, const uint8_t polarity) : It takes channel and polarity to be assigned and sets polarity of that channel to the specified value using file system. If pwmSetPolarity() is successful then 0 is returned otherwise -1 is returned.
Returns : 0 on success and -1 if it fails.
Example :
int ret = pwmSetPolarity(0, 1); //It sets polarity of channel 0.
- int pwmGetPolarity(const uint8_t channel) : It takes channel number as input and returns the value of polarity of specified channel.
Returns : value of polarity on success and -1 if it fails.
Example :
int polarity = pwmGetPolarity(0); // It returns polarity of channel 0.
- int pwmRun(const uint8_t channel) : It takes channel number as input and sets run for that channel so that pwm starts running for that channel.
Returns : 0 on success and -1 if it fails.
Example :
int ret = pwmRun(0); // It starts pwm channel 0.
- int pwmStop(const uint8_t channel) : It takes channel number as input and sets run to 0 for that channel so that pwm stops for that channel.
Returns : 0 on success and -1 if it fails.
Example :
int ret = pwmStop(0); // It stops pwm channel 0.
- int pwmRunCheck(const uint8_t channel) : It takes channel number as input and returns the value of run for that channel.
Returns : value of run on success and -1 if it fails.
Example :
int runcheck = pwmRunCheck(0); // It it used to check if channel 0 is running.
###Screenshot of PWM android application