4 1/ mmap /dev/mem to have write access to system clock
5 2/ enable system clock (0x0 = disabled, 0x02 = enabled)
8 can modify pwm variables through virtual filesystem:
9 "/sys/class/pwm/ehrpwm.1:0/..."
11 pwm drivers reference:
12 http://processors.wiki.ti.com/index.php/AM335x_PWM_Driver%27s_Guide */
18 volatile uint32_t *epwmss1;
20 int fd = open("/dev/mem", O_RDWR);
24 printf("Can't open /dev/mem\n");
28 epwmss1 = (volatile uint32_t *) mmap(NULL, LENGTH, PROT_READ|PROT_WRITE, MAP_SHARED, fd, START);
31 printf("Can't mmap\n");
36 epwmss1[OFFSET_1 / sizeof(uint32_t)] = 0x2;
40 pwm_mux = fopen("/sys/kernel/debug/omap_mux/gpmc_a2", "w");
41 fprintf(pwm_mux, "6"); // pwm is mux mode 6
45 //can change filepath of pwm module "/ehrpwm.%d:0/" by passing %d as argument
46 //depends how many pwm modules we have to run
52 pwm_run = fopen("/sys/class/pwm/ehrpwm.1:0/run", "w");
53 fprintf(pwm_run, "1");
61 pwm_run = fopen("/sys/class/pwm/ehrpwm.1:0/run", "w");
62 fprintf(pwm_run, "0");
66 //duty_percent is just a regular percentage (i.e. 50 = 50%)
68 void pwm_set_duty(int duty_percent)
72 pwm_duty = fopen("/sys/class/pwm/ehrpwm.1:0/duty_percent", "w");
73 fprintf(pwm_duty, "%d", duty_percent);
77 //freq is just normal frequency (i.e. 100 = 100Hz)
79 void pwm_set_period(int freq)
83 pwm_period = fopen("/sys/class/pwm/ehrpwm.1:0/period_freq", "w");
84 fprintf(pwm_period, "%d", freq);