📄 psc_drv.c
字号:
//! @file psc_drv.c
//!
//! Copyright (c) 2004
//!
//! Please read file license.txt for copyright notice.
//!
//! @brief This file contains the low level functions for the PSC
//!
//! @version 1.5 (pwm3-ac-ctrl-motor-0_0_3)
//!
//! @todo
//! @bug
//_____ I N C L U D E S ___________________________________________________
#include "config.h"
#include "lib_mcu/psc/psc_drv.h"
#include "lib_mcu/pll/pll_drv.h"
//_____ M A C R O S ________________________________________________________
//_____ P R I V A T E D E C L A R A T I O N _____________________________
//_____ D E F I N I T I O N ________________________________________________
//_____ D E C L A R A T I O N ______________________________________________
#ifdef USE_PSC0 //!< this define is set on config.h file
//! Configures the PSC0 accordingly to the PSC0 Define Configuration values.
//!
//! @param None.
//!
//! @pre - Define the configuration in config.h file
//!
//! @post - Set the psc0 comparison values
//! - Start the PSC0 thanks to Start_psc0() macro
void init_psc0(void)
{
# if (PSC0_PLL_FREQUENCY == 64)
Start_pll_64_mega();
# elif (PSC0_PLL_FREQUENCY == 32)
Start_pll_32_mega();
# elif (PSC0_PLL_FREQUENCY == 0)
# else
# error (PSC0_PLL_FREQUENCY should be 0, 32, or 64... See config.h file)
# endif
# if (PSC0_OUTPUT_SELECTION == 3)
Enable_both_psc0_outputs();
# elif (PSC0_OUTPUT_SELECTION == 2)
Enable_pscout01();
# elif (PSC0_OUTPUT_SELECTION == 1)
Enable_pscout00();
# elif (PSC0_OUTPUT_SELECTION == 0)
Disable_both_psc0_outputs();
# else
# error (PSC0_OUTPUT_SELECTION should be 0, 1, 2, or 2... See config.h file)
# endif
# if (PSC0_ACTIVE_STATE == 1)
Psc0_outputs_active_high();
# elif (PSC0_ACTIVE_STATE == 0)
Psc0_outputs_active_low();
# else
# error (PSC0_ACTIVE_STATE should be 0, or 1... See config.h file)
# endif
# if (PSC0_RAMP_MODE == 4)
Psc0_in_4_ramps_mode();
# elif (PSC0_RAMP_MODE == 2)
Psc0_in_2_ramps_mode();
# elif (PSC0_RAMP_MODE == 1)
Psc0_in_1_ramp_mode();
# elif (PSC0_RAMP_MODE == 0)
Psc0_in_centered_aligne_mode();
# else
# error (PSC0_RAMP_MODE should be 0, 1, 3, or 4... See config.h file)
# endif
# if (PSC0_FIFTY_PERCENT_MODE == 1)
Enable_psc0_fifty_percent_mode();
# elif (PSC0_FIFTY_PERCENT_MODE == 0)
Disable_psc0_fifty_percent_mode();
# else
# error (PSC0_FIFTY_PERCENT_MODE should be 0, or 1)
# endif
# if (PSC0_SYMETRICAL_FLANK_WIDTH_MODULATION == 1)
Psc0_symetrical_flank_width_modulation();
# elif (PSC0_SYMETRICAL_FLANK_WIDTH_MODULATION == 0)
Psc0_end_of_cycle_flank_width_modulation();
# else
# error (PSC0_SYMETRICAL_FLANK_WIDTH_MODULATION should be 0, or 1... See config.h file)
# endif
# if (PSC0_AUTOLOCK_MODE == 1)
Enable_psc0_autolock_mode();
# elif (PSC0_AUTOLOCK_MODE == 0)
Disable_psc0_autolock_mode();
# else
# error (PSC0_AUTOLOCK_MODE should be 0, or 1... See config.h file)
# endif
# if (PSC0_PRESCALER_DIVIDER == 64)
Divide_psc0_input_clock_by_64();
# elif (PSC0_PRESCALER_DIVIDER == 16)
Divide_psc0_input_clock_by_16();
# elif (PSC0_PRESCALER_DIVIDER == 4)
Divide_psc0_input_clock_by_4();
# elif (PSC0_PRESCALER_DIVIDER == 0)
Disable_psc0_prescaler();
# else
# error (PSC0_PRESCALER_DIVIDER should be 0, 4, 16, or 64... See config.h file)
# endif
# if (PSC0_PLL_FREQUENCY == 64)
Wait_pll_ready();
Psc0_use_pll_clock();
# elif (PSC0_PLL_FREQUENCY == 32)
Wait_pll_ready();
Psc0_use_pll_clock();
# elif (PSC0_PLL_FREQUENCY == 0)
Psc0_use_io_clock();
# else
# error (PSC0_PLL_FREQUENCY should be 0, 32, or 64... See config.h file)
# endif
}
//! Update all the PSC0 comparison values accordingly to the four values
//! passed as Psc_comparison_values typedef.
//!
//! @param Comparison values via U16.
//! psc0_comparison_values->deadtime0 (=) U16 deadtime0
//! psc0_comparison_values->ontime0 (=) U16 ontime0
//! psc0_comparison_values->deadtime1 (=) U16 deadtime1
//! psc0_comparison_values->ontime1 (=) U16 ontime1
//!
void update_psc0 ( Psc_comparison_values *psc0_comparison_values )
{
Lock_psc0_compare_values();
OCR0SAH = HIGH(psc0_comparison_values->deadtime0);
OCR0SAL = LOW (psc0_comparison_values->deadtime0);
OCR0RAH = HIGH(psc0_comparison_values->ontime0);
OCR0RAL = LOW (psc0_comparison_values->ontime0);
OCR0SBH = HIGH(psc0_comparison_values->deadtime1);
OCR0SBL = LOW (psc0_comparison_values->deadtime1);
OCR0RBH = HIGH(psc0_comparison_values->ontime1);
OCR0RBL = LOW (psc0_comparison_values->ontime1);
Update_psc0_compare_values();
}
//! Update half the PSC0 comparison values accordingly to the two values
//! passed as Psc_fifty_percent_comparison_values typedef.
//! This function is usefull if the PSC0 is configured in fifty percent mode
//!
//! @param Comparison values via U16.
//! psc0_fifty_percent_comparison_values->deadtime1 (=) U16 deadtime1
//! psc0_fifty_percent_comparison_values->ontime1 (=) U16 ontime1
//!
void update_psc0_fifty ( Psc_fifty_percent_comparison_values *psc0_fifty_percent_comparison_values )
{
Lock_psc0_compare_values();
OCR0SBH = HIGH(psc0_fifty_percent_comparison_values->deadtime1);
OCR0SBL = LOW (psc0_fifty_percent_comparison_values->deadtime1);
OCR0RBH = HIGH(psc0_fifty_percent_comparison_values->ontime1);
OCR0RBL = LOW (psc0_fifty_percent_comparison_values->ontime1);
Update_psc0_compare_values();
}
#endif // USE_PFC0
#ifdef USE_PSC1 //!< this define is set on config.h file
//! Configures the PSC1 accordingly to the PSC1 Define Configuration values.
//!
//! @param None.
//!
//! @pre - Define the configuration in config.h file
//!
//! @post - Set the psc1 comparison values
//! - Start the PSC1 thanks to Start_psc1() macro
void init_psc1(void)
{
# if (PSC1_PLL_FREQUENCY == 64)
Start_pll_64_mega();
# elif (PSC1_PLL_FREQUENCY == 32)
Start_pll_32_mega();
# elif (PSC1_PLL_FREQUENCY == 0)
# else
# error (PSC1_PLL_FREQUENCY should be 0, 32, or 64... See config.h file)
# endif
# if (PSC1_OUTPUT_SELECTION == 3)
Enable_both_psc1_outputs();
# elif (PSC1_OUTPUT_SELECTION == 2)
Enable_pscout11();
# elif (PSC1_OUTPUT_SELECTION == 1)
Enable_pscout10();
# elif (PSC1_OUTPUT_SELECTION == 0)
Disable_both_psc1_outputs();
# else
# error (PSC1_OUTPUT_SELECTION should be 0, 1, 2, or 2... See config.h file)
# endif
# if (PSC1_ACTIVE_STATE == 1)
Psc1_outputs_active_high();
# elif (PSC1_ACTIVE_STATE == 0)
Psc1_outputs_active_low();
# else
# error (PSC1_ACTIVE_STATE should be 0, or 1... See config.h file)
# endif
# if (PSC1_RAMP_MODE == 4)
Psc1_in_4_ramps_mode();
# elif (PSC1_RAMP_MODE == 2)
Psc1_in_2_ramps_mode();
# elif (PSC1_RAMP_MODE == 1)
Psc1_in_1_ramp_mode();
# elif (PSC1_RAMP_MODE == 0)
Psc1_in_centered_aligned_mode();
# else
# error (PSC1_RAMP_MODE should be 0, 1, 3, or 4... See config.h file)
# endif
# if (PSC1_FIFTY_PERCENT_MODE == 1)
Enable_psc1_fifty_percent_mode();
# elif (PSC1_FIFTY_PERCENT_MODE == 0)
Disable_psc1_fifty_percent_mode();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -