RocketLogger  1.1
pwm.h
Go to the documentation of this file.
1 
31 #ifndef PWM_H_
32 #define PWM_H_
33 
34 #include <errno.h>
35 #include <fcntl.h>
36 #include <stdint.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <sys/mman.h>
40 #include <sys/stat.h>
41 #include <unistd.h>
42 
43 #include "log.h"
44 #include "types.h"
45 
46 // base addresses
48 #define PWMSS0_BASE 0x48300000
49 #define PWMSS1_BASE 0x48302000
51 #define EPWM_OFFSET 0x0200
53 
54 // pwm size
56 #define PWM_SIZE 0x00000FFF
57 
58 // configuration registers
60 #define TBCTL (EPWM_OFFSET + 0x0) / sizeof(uint16_t) // counter control
61 #define TBPRD (EPWM_OFFSET + 0xA) / sizeof(uint16_t) // period
63 #define CMPA (EPWM_OFFSET + 0x12) / sizeof(uint16_t) // compare
65 #define CMPB (EPWM_OFFSET + 0x14) / sizeof(uint16_t)
67 #define AQCTLA (EPWM_OFFSET + 0x16) / sizeof(uint16_t) // action qualifier
69 #define AQCTLB (EPWM_OFFSET + 0x18) / sizeof(uint16_t)
71 
72 // register values
74 #define TBCTL_DEFAULT 0xC000
75 #define UP_DOWN_COUNT 0x0002
77 #define PRESCALE2 0x0400
79 
80 // range switch clock configuration (action qualifier)
82 #define RWC_AQ_A 0x0060 // set when incrementing, clear when decrementing
83 #define RWC_AQ_B 0x0900 // set when decrementing, clear when incrementing
85 
86 // pulse configuration
88 #define PULSE_WIDTH 0.1 // 10% of sampling period
89 #define MARGIN 0.1
91 #define PWM_PERIOD_SCALE \
93  50000000 * \
94  (1 + PULSE_WIDTH + MARGIN) // period scaling factor (period is set in
95  // 5ns, (/2 clock prescaling))
96 
97 // ADC clock settings
99 #define ADC_CLOCK_PERIOD 48 // in 10ns
100 #define ADC_AQ 0x0025 // clear on zero and period, set at 50%
102 
103 int pwm_setup(void);
104 void pwm_close(void);
105 
106 void pwm_setup_range_clock(int sample_rate);
107 void pwm_setup_adc_clock(void);
108 
109 #endif /* PWM_H_ */
void pwm_setup_adc_clock(void)
Definition: pwm.c:114
int pwm_setup(void)
Definition: pwm.c:45
void pwm_close(void)
Definition: pwm.c:79
void pwm_setup_range_clock(int sample_rate)
Definition: pwm.c:93