/* * EPWM.h * * Author: Aleksey Gerasimenko * gerasimenko.aleksey.n@gmail.com */ #include "F28335/DSP28x_Project.h" #include "DSP28335/CPUBase.h" #ifndef DSP28335_EPWM_H_ #define DSP28335_EPWM_H_ namespace DSP28335 { enum CLOCKPRESCALE {DIV01, DIV02, DIV04, DIV08, DIV16, DIV32, DIV64, DIV128}; enum HIGHSPEEDCLOCKPRESCALE {HSDIV01, HSDIV02, HSDIV04, HSDIV06, HSDIV08, HSDIV10, HSDIV12, HSDIV14}; struct EPWMStatusBitField { Uint16 new_cycle:1; Uint16 adc_soc:1; Uint16 adc_ready:1; };//EPWMStatusBitField union EPWMStatusRegister { Uint16 all; EPWMStatusBitField bit; EPWMStatusRegister(): all(0) {} };//EPWMStatusRegister struct EPWMConfiguration { float fpwm; float pulse_sync; float pulse_adc_soc; float adc_soc_offset; Uint16 adc_soc_quantity; EPWMConfiguration(): fpwm(500.0), pulse_sync(1.0e-6), pulse_adc_soc(10.0e-6), adc_soc_offset(FP_ZERO), adc_soc_quantity(1) {} };//EPWMConfiguration class EPWMConfigModificator { private: EPWMConfiguration m_config; public: bool modify; public: EPWMConfigModificator(); void set_config(EPWMConfiguration& refconfig); EPWMConfiguration get_config(); public: void reset(); public: void set_pwm_frquency(float fpwm); void set_pulse_sync(float pulse_sync); void set_pulse_adc_soc(float pulse_adc_soc); void set_adc_soc_offset(float adc_soc_offset); void set_adc_soc_quantity(Uint16 adc_soc_quantity); public: float get_pwm_frquency(); float get_pulse_sync(); float get_pulse_adc_soc(); float get_adc_soc_offset(); Uint16 get_adc_soc_quantity(); // };//EPWMConfigModificator struct EPWMSetup: public DSP28335::CPUBaseSetup { EPWMConfiguration parameters; EPWMSetup(): DSP28335::CPUBaseSetup(), parameters() {} };//EPWMSetup class EPWM: public DSP28335::CPUBase { private: EPWMConfiguration m_configuration_current; EPWMConfiguration m_configuration_new; private: float m_fcpu; float m_timer_period; float m_timer_step; float m_time_sample_adc; float m_clock_prescale_list[8]; float m_high_speed_clock_prescale[8]; Uint16 m_tbprd; //TBPRD Uint16 m_clkdiv; Uint16 m_hspclkdiv; Uint16 m_cmpr_sync; Uint16 m_cmpr_adc_offset; Uint16 m_cmpr_adc_start; Uint16 m_cmpr_adc_stop; Uint16 m_cmpr_adc_width; Uint16 m_cmpr_adc_step; Uint16 m_adc_soc_quantity; Uint16 m_adc_soc_counter; public: EPWMStatusRegister status; public: EPWM(); void setup(const EPWMSetup& setup); void configure(const EPWMConfiguration& config); public: void set_actions(); void clear_actions(); public: float get_time_sample_adc(); public: void epwm1_adc_drive(); public: void epwm2_adc_drive(); private: void (EPWM::*_epwm2_adc_drive)(); void _epwm2_adc_drive_mode_start(); void _epwm2_adc_drive_mode_stop(); public: void epwm1_interrupt_ack(); void epwm2_interrupt_ack(); private: void (*_gpio_setup)(); }; } /* namespace DSP28335 */ #endif /* DSP28335_EPWM_H_ */