RocketLogger  1.1.6
pwm.h
Go to the documentation of this file.
1 
32 #ifndef PWM_H_
33 #define PWM_H_
34 
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <stdint.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <sys/mman.h>
41 #include <sys/stat.h>
42 #include <unistd.h>
43 
44 #include "log.h"
45 #include "types.h"
46 
47 // base addresses
49 #define PWMSS0_BASE 0x48300000
50 #define PWMSS1_BASE 0x48302000
52 #define EPWM_OFFSET 0x0200
54 
55 // pwm size
57 #define PWM_SIZE 0x00000FFF
58 
59 // configuration registers
61 #define TBCTL (EPWM_OFFSET + 0x0) / sizeof(uint16_t) // counter control
62 #define TBPRD (EPWM_OFFSET + 0xA) / sizeof(uint16_t) // period
64 #define CMPA (EPWM_OFFSET + 0x12) / sizeof(uint16_t) // compare
66 #define CMPB (EPWM_OFFSET + 0x14) / sizeof(uint16_t)
68 #define AQCTLA (EPWM_OFFSET + 0x16) / sizeof(uint16_t) // action qualifier
70 #define AQCTLB (EPWM_OFFSET + 0x18) / sizeof(uint16_t)
72 
73 // register values
75 #define TBCTL_DEFAULT 0xC000
76 #define UP_DOWN_COUNT 0x0002
78 #define PRESCALE2 0x0400
80 
81 // range switch clock configuration (action qualifier)
83 #define RWC_AQ_A 0x0060 // set when incrementing, clear when decrementing
84 #define RWC_AQ_B 0x0900 // set when decrementing, clear when incrementing
86 
87 // pulse configuration
89 #define PULSE_WIDTH 0.1 // 10% of sampling period
90 #define MARGIN 0.1
92 #define PWM_PERIOD_SCALE \
94  50000000 * \
95  (1 + PULSE_WIDTH + MARGIN) // period scaling factor (period is set in
96  // 5ns, (/2 clock prescaling))
97 
98 // ADC clock settings
100 #define ADC_CLOCK_PERIOD 48 // in 10ns
101 #define ADC_AQ 0x0025 // clear on zero and period, set at 50%
103 
104 int pwm_setup(void);
105 void pwm_close(void);
106 
107 void pwm_setup_range_clock(int sample_rate);
108 void pwm_setup_adc_clock(void);
109 
110 #endif /* PWM_H_ */
void pwm_setup_adc_clock(void)
Definition: pwm.c:115
int pwm_setup(void)
Definition: pwm.c:46
void pwm_close(void)
Definition: pwm.c:80
void pwm_setup_range_clock(int sample_rate)
Definition: pwm.c:94