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 */
14 static int pwminit = 0;
15 static int pwmstart = 0;
20 volatile uint32_t *epwmss1;
22 int fd = open("/dev/mem", O_RDWR);
26 printf("Can't open /dev/mem\n");
30 epwmss1 = (volatile uint32_t *) mmap(NULL, LENGTH, PROT_READ|PROT_WRITE, MAP_SHARED, fd, START);
33 printf("Can't mmap\n");
38 epwmss1[OFFSET_1 / sizeof(uint32_t)] = 0x2;
42 pwm_mux = fopen(PWMMuxPath, "w");
43 fprintf(pwm_mux, "6"); // pwm is mux mode 6
47 //can change filepath of pwm module "/ehrpwm.%d:0/" by passing %d as argument
48 //depends how many pwm modules we have to run
51 void pwm_start(void) {
53 pwm_run = fopen(PWMRunPath, "w");
54 fprintf(pwm_run, "1");
61 pwm_run = fopen(PWMRunPath, "w");
62 fprintf(pwm_run, "0");
67 //duty_percent is just a regular percentage (i.e. 50 = 50%)
69 void pwm_set_duty(int duty_percent) {
71 pwm_duty = fopen(PWMDutyPath, "w");
72 fprintf(pwm_duty, "%d", duty_percent);
76 //freq is just normal frequency (i.e. 100 = 100Hz)
78 void pwm_set_period(int freq) {
80 pwm_period = fopen(PWMFreqPath, "w");
81 fprintf(pwm_period, "%d", freq);