4 * Created on: 22.2.2013
7 * This file provides functions and procedures to manipulate HOUT port.
9 * Functions for setting, starting and stopping PWM on selected HOUT pin.
13 /** PWM modules from N2HET mapped to HOUT pin ID 0-5 **/
14 static uint8_t hout_pwm_map[PORT_NV_HOUTIN] = {pwm1, pwm2, pwm3, pwm4, pwm5, pwm6};
15 /** Flags, if pwm for each HOUT pin was set a period and duty, so it can be started. **/
16 uint8_t hout_pwm_initialized = 0;
19 * @brief Set PWM period and duty cycle to HOUT pin
21 * Set period and dutycycle to HOUT pin.
22 * Period is expected to be in us, duty cycle in percent of the period,
23 * hout_id is indexing HOUT pin 0-5.
25 * If period is lower than 1, duty greater than 100 or hout_id out of range <0;5>,
26 * function returns without having effect.
28 * @param[in] hout_id ID of HOUT pin from range 0-5
29 * @param[in] period Period of PWM in us
30 * @param[in] duty Width of duty in %
32 void hout_pwm_set_signal(uint8_t hout_id, double period, uint32_t duty) {
33 hetSIGNAL_t tmp_signal;
34 if (duty > 100) return;
35 if (period < 1) return;
36 tmp_signal.duty = duty;
37 tmp_signal.period = period;
38 pwmSetSignal(hetRAM1, hout_pwm_map[hout_id], tmp_signal);
39 hout_pwm_initialized |= 1 << hout_id;
43 * @brief Start PWM on HOUT pin
45 * If PWM was set previously by hout_pwm_set_signal function, this procedure starts it.
46 * Otherwise function returns and PWM is not started.
48 * @param[in] hout_id ID of HOUT pin from range 0-5
49 * @return 0 if success, -1 when PWM was not yes set.
51 int hout_pwm_start(uint8_t hout_id) {
52 if (hout_pwm_initialized & (1 << hout_id)) {
53 pwmStart(hetRAM1, hout_pwm_map[hout_id]);
62 * @brief Stop PWM on HOUT pin
64 * @param[in] hout_id ID of HOUT pin from range 0-5
66 void hout_pwm_stop(uint8_t hout_id) {
67 pwmStop(hetRAM1, hout_pwm_map[hout_id]);
71 * @brief Get duty width of PWM on HOUT pin
73 * @param[in] hout_id ID of HOUT pin from range 0-5
74 * @return Duty width of PWM in %
76 uint32_t hout_pwm_get_duty(uint8_t hout_id) {
77 hetSIGNAL_t tmp_signal;
78 tmp_signal = pwmGetSignal(hetRAM1, hout_pwm_map[hout_id]);
79 return tmp_signal.duty;
83 * @brief Get period of PWM on HOUT pin
85 * @param[in] hout_id ID of HOUT pin from range 0-5
86 * @return Period of PWM in us
88 double hout_pwm_get_period(uint8_t hout_id) {
89 hetSIGNAL_t tmp_signal;
90 tmp_signal = pwmGetSignal(hetRAM1, hout_pwm_map[hout_id]);
91 return tmp_signal.period;