Rev 1 | Rev 238 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 196 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /******************** (C) COPYRIGHT 2006 STMicroelectronics ******************** |
1 | /******************** (C) COPYRIGHT 2008 STMicroelectronics ******************** |
2 | * File Name : 91x_mc.c |
2 | * File Name : 91x_mc.c |
3 | * Author : MCD Application Team |
3 | * Author : MCD Application Team |
- | 4 | * Version : V2.1 |
|
4 | * Date First Issued : 05/18/2006 : Version 1.0 |
5 | * Date : 12/22/2008 |
5 | * Description : This file provides all the MC software functions. |
6 | * Description : This file provides all the MC firmware functions. |
6 | ******************************************************************************** |
7 | ******************************************************************************** |
7 | * History: |
- | |
8 | * 05/22/2007 : Version 1.2 |
- | |
9 | * 05/24/2006 : Version 1.1 |
- | |
10 | * 05/18/2006 : Version 1.0 |
- | |
11 | ******************************************************************************** |
- | |
12 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
8 | * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH |
13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
9 | * CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS |
14 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
10 | * A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT |
15 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
11 | * OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT |
16 | * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
12 | * OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION |
17 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
13 | * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
18 | *******************************************************************************/ |
14 | *******************************************************************************/ |
Line -... | Line 15... | ||
- | 15 | ||
19 | 16 | ||
20 | /* Includes ------------------------------------------------------------------*/ |
17 | /* Standard include ----------------------------------------------------------*/ |
21 | #include "91x_mc.h" |
18 | #include "91x_mc.h" |
22 | #include "91x_scu.h" |
19 | #include "91x_scu.h" |
23 | /* Private typedef -----------------------------------------------------------*/ |
20 | /* Private typedef -----------------------------------------------------------*/ |
24 | /* Private define ------------------------------------------------------------*/ |
21 | /* Private define ------------------------------------------------------------*/ |
Line 101... | Line 98... | ||
101 | #define MC_ESC_Clear 0x4321 |
98 | #define MC_ESC_Clear 0x4321 |
Line 102... | Line 99... | ||
102 | 99 | ||
103 | #define MC_PCR1_TIN_MASK 0xFFFC |
100 | #define MC_PCR1_TIN_MASK 0xFFFC |
104 | #define MC_OPR_Mask 0x0040 |
101 | #define MC_OPR_Mask 0x0040 |
- | 102 | #define MC_UDCS_Mask 0x0002 |
|
- | 103 | ||
- | 104 | ||
- | 105 | ||
105 | #define MC_UDCS_Mask 0x0002 |
106 | |
106 | /* Private function prototypes -----------------------------------------------*/ |
107 | /* Private function prototypes -----------------------------------------------*/ |
- | 108 | /* Private functions ---------------------------------------------------------*/ |
|
107 | /* Private functions ---------------------------------------------------------*/ |
109 | |
108 | /****************************************************************************** |
110 | /****************************************************************************** |
109 | * Function Name : MC_DeInit |
111 | * Function Name : MC_DeInit |
110 | * Description : Deinitializes MC peripheral registers to their default reset |
112 | * Description : Deinitializes MC peripheral registers to their default reset |
111 | * values. |
113 | * values. |
Line 119... | Line 121... | ||
119 | SCU_APBPeriphReset(__MC, ENABLE); |
121 | SCU_APBPeriphReset(__MC, ENABLE); |
Line 120... | Line 122... | ||
120 | 122 | ||
121 | /* MC peripheral Reset off */ |
123 | /* MC peripheral Reset off */ |
122 | SCU_APBPeriphReset(__MC, DISABLE); |
124 | SCU_APBPeriphReset(__MC, DISABLE); |
123 | } |
- | |
124 | 125 | } |
|
125 | /******************************************************************************* |
126 | /******************************************************************************* |
126 | * Function Name : MC_Init |
127 | * Function Name : MC_Init |
127 | * Description : Initializes the MC peripheral according to the specified |
128 | * Description : Initializes the MC peripheral according to the specified |
128 | * parameters in the MC_InitStruct . |
129 | * parameters in the MC_InitStruct . |
Line 381... | Line 382... | ||
381 | * Output : None |
382 | * Output : None |
382 | * Return : None. |
383 | * Return : None. |
383 | *******************************************************************************/ |
384 | *******************************************************************************/ |
384 | void MC_StructInit(MC_InitTypeDef* MC_InitStruct) |
385 | void MC_StructInit(MC_InitTypeDef* MC_InitStruct) |
385 | { |
386 | { |
- | 387 | ||
- | 388 | u16 temp; |
|
- | 389 | temp=MC->ECR; |
|
- | 390 | temp &= MC_PWM_Counter ; |
|
- | 391 | ||
386 | MC_InitStruct->MC_OperatingMode = MC_HardwareOperating_Mode; |
392 | MC_InitStruct->MC_OperatingMode = MC_HardwareOperating_Mode; |
387 | MC_InitStruct->MC_TachoMode = MC_TachoContinuous_Mode; |
393 | MC_InitStruct->MC_TachoMode = MC_TachoContinuous_Mode; |
388 | MC_InitStruct->MC_TachoEvent_Mode = MC_TachoEvent_Hardware_Mode; |
394 | MC_InitStruct->MC_TachoEvent_Mode = MC_TachoEvent_Hardware_Mode; |
389 | MC_InitStruct->MC_Prescaler = 0x00; |
395 | MC_InitStruct->MC_Prescaler = 0x00; |
390 | MC_InitStruct->MC_TachoPrescaler = 0x0000; |
396 | MC_InitStruct->MC_TachoPrescaler = 0x0000; |
Line 403... | Line 409... | ||
403 | MC_InitStruct->MC_PolarityVL = MC_Polarity_NonInverted; |
409 | MC_InitStruct->MC_PolarityVL = MC_Polarity_NonInverted; |
404 | MC_InitStruct->MC_PolarityVH = MC_Polarity_NonInverted; |
410 | MC_InitStruct->MC_PolarityVH = MC_Polarity_NonInverted; |
405 | MC_InitStruct->MC_PolarityWL = MC_Polarity_NonInverted; |
411 | MC_InitStruct->MC_PolarityWL = MC_Polarity_NonInverted; |
406 | MC_InitStruct->MC_PolarityWH = MC_Polarity_NonInverted; |
412 | MC_InitStruct->MC_PolarityWH = MC_Polarity_NonInverted; |
407 | MC_InitStruct->MC_TachoPolarity = MC_TachoEventEdge_RisingFalling; |
413 | MC_InitStruct->MC_TachoPolarity = MC_TachoEventEdge_RisingFalling; |
- | 414 | ||
- | 415 | if(temp==0) |
|
- | 416 | { |
|
408 | MC_InitStruct->MC_DeadTime = 0x003F; |
417 | MC_InitStruct->MC_DeadTime = 0x003F; |
- | 418 | } |
|
- | 419 | else |
|
- | 420 | { |
|
- | 421 | MC_InitStruct->MC_DeadTime = 0x03FF; |
|
- | 422 | } |
|
- | 423 | ||
409 | MC_InitStruct->MC_RepetitionCounter = 0x0000; |
424 | MC_InitStruct->MC_RepetitionCounter = 0x0000; |
410 | } |
425 | } |
Line 411... | Line 426... | ||
411 | 426 | ||
412 | /******************************************************************************* |
427 | /******************************************************************************* |
413 | * Function Name : MC_Cmd |
428 | * Function Name : MC_Cmd |
Line 669... | Line 684... | ||
669 | * Output : None |
684 | * Output : None |
670 | * Return : None |
685 | * Return : None |
671 | *******************************************************************************/ |
686 | *******************************************************************************/ |
672 | void MC_EmergencyClear(void) |
687 | void MC_EmergencyClear(void) |
673 | { |
688 | { |
674 | /* Force PWM outputs in safe state (All OFF) */ |
- | |
675 | MC->OPR |= MC_ODS_Set; |
689 | MC->ECR |= 0x0100; |
676 | 690 | ||
677 | /* Clear EST bit */ |
691 | /* Clear EST bit */ |
678 | MC->ESC = MC_ESC_Clear; |
692 | MC->ESC = MC_ESC_Clear; |
679 | - | ||
680 | /* Re-enable protection */ |
- | |
681 | MC->ESC = 0; |
- | |
682 | - | ||
683 | /* Enables the Outputs */ |
- | |
684 | MC->OPR &= MC_ODS_Reset; |
- | |
685 | } |
693 | } |
Line 686... | Line 694... | ||
686 | 694 | ||
687 | /******************************************************************************* |
695 | /******************************************************************************* |
688 | * Function Name : MC_GetPeriod |
696 | * Function Name : MC_GetPeriod |
Line 928... | Line 936... | ||
928 | { |
936 | { |
929 | /* Clear the corresponding interrupt pending bit */ |
937 | /* Clear the corresponding interrupt pending bit */ |
930 | MC->IPR &= ~MC_IT; |
938 | MC->IPR &= ~MC_IT; |
931 | } |
939 | } |
Line -... | Line 940... | ||
- | 940 | ||
- | 941 | ||
- | 942 | /******************************************************************************* |
|
- | 943 | * Function Name : MC_Lock |
|
- | 944 | * Description : Enables the lock of certain control register bits |
|
- | 945 | * Input : - MC_LockLevel: Specifies the level to be locked. |
|
- | 946 | * This parameter can be any combination of the following values: |
|
- | 947 | * - MC_LockLevel4: Lock Dead Time Generator register. |
|
- | 948 | * - MC_LockLevel3: Lock Output Peripheral Register. |
|
- | 949 | * - MC_LockLevel2: Lock phase polarity bits. |
|
- | 950 | * - MC_LockLevel1: Lock Emergency Stop Disable bit. |
|
- | 951 | * - MC_LockLevel0: Dead Time Enable and Output Dead Time |
|
- | 952 | * counter Selection bits. |
|
- | 953 | * Output : None |
|
- | 954 | * Return : None |
|
- | 955 | *******************************************************************************/ |
|
- | 956 | void MC_Lock(u16 MC_LockLevel) |
|
- | 957 | { |
|
- | 958 | MC->LOK &= ~MC_LockLevel; |
|
- | 959 | MC->LOK |= MC_LockLevel; |
|
- | 960 | } |
|
- | 961 | ||
- | 962 | /****************************************************************************** |
|
- | 963 | * Function Name : MC_CounterModeConfig |
|
- | 964 | * Description : Enables the 10 bits mode for the dead time counter or enables |
|
- | 965 | * the 16 bits mode for the PWM counter. |
|
- | 966 | * Input : - MC_Counter : Specifies the counter |
|
- | 967 | * This parameter can be any combination of the following values: |
|
- | 968 | * - MC_DT_Counter : Dead Time Counter is in 10 bits mode. |
|
- | 969 | * - MC_PWM_Counter : PWM_Counter is in 16 bits mode. |
|
- | 970 | * Output : None |
|
- | 971 | * Return : None |
|
- | 972 | *******************************************************************************/ |
|
- | 973 | void MC_CounterModeConfig(u16 MC_Counter) |
|
- | 974 | { |
|
- | 975 | MC->ECR &= ~MC_Counter; |
|
- | 976 | MC->ECR |= MC_Counter; |
|
- | 977 | } |
|
- | 978 | ||
- | 979 | /******************************************************************************* |
|
- | 980 | * Function Name : MC_DoubleUpdateMode |
|
- | 981 | * Description : Enables or disables the Double Update Mode for the MC |
|
- | 982 | * Input : - Newstate: New state of the double update mode. |
|
- | 983 | * This parameter can be: ENABLE or DISABLE. |
|
- | 984 | * Output : None |
|
- | 985 | * Return : None |
|
- | 986 | *******************************************************************************/ |
|
- | 987 | void MC_DoubleUpdateMode(FunctionalState NewState) |
|
- | 988 | { |
|
- | 989 | if( NewState==ENABLE) |
|
- | 990 | { |
|
- | 991 | MC->ECR |= MC_DUM; |
|
- | 992 | } |
|
- | 993 | else |
|
- | 994 | { |
|
- | 995 | MC->ECR &= ~MC_DUM; |
|
- | 996 | } |
|
- | 997 | } |
|
- | 998 | ||
- | 999 | /******************************************************************************* |
|
- | 1000 | * Function Name : MC_ADCTrigger |
|
- | 1001 | * Description : Enables or disables the Triggers to the ADC conversion |
|
- | 1002 | * Input : IMC event : The IMC event to trigger the ADC conversion |
|
- | 1003 | * This parameter can be one of the following values: |
|
- | 1004 | * - MC_ZPC : When the PWM counter reaches zero. |
|
- | 1005 | * - MC_CM0 : When the PWM counter reaches its maximum |
|
- | 1006 | * count. |
|
- | 1007 | * - MC_ADT : When the PWM counter equals zero and the |
|
- | 1008 | * Repetition Down counter equals zero. |
|
- | 1009 | * - Newstate: New state of the ADC trigger event. |
|
- | 1010 | * This parameter can be: ENABLE or DISABLE. |
|
- | 1011 | * Output : None |
|
- | 1012 | * Return : None |
|
- | 1013 | *******************************************************************************/ |
|
- | 1014 | void MC_ADCTrigger(u16 IMC_Event, FunctionalState NewState) |
|
- | 1015 | { |
|
- | 1016 | MC->ECR &= 0x01F3; |
|
- | 1017 | ||
- | 1018 | if( NewState==ENABLE) |
|
- | 1019 | { |
|
- | 1020 | MC->ECR |= IMC_Event; |
|
- | 1021 | } |
|
- | 1022 | else |
|
- | 1023 | { |
|
- | 1024 | MC->ECR &= ~IMC_Event; |
|
- | 1025 | } |
|
- | 1026 | } |
|
- | 1027 | ||
- | 1028 | ||
- | 1029 | /******************************************************************************* |
|
- | 1030 | * Function Name : MC_EnhancedStop |
|
- | 1031 | * Description : Enables or disables an Enhanced Motor Stop feature. |
|
- | 1032 | * Input : NewState : This pararameter can be ENABLE or DISABLE. |
|
- | 1033 | * Output : None |
|
- | 1034 | * Return : None |
|
- | 1035 | *******************************************************************************/ |
|
- | 1036 | void MC_EnhancedStop(FunctionalState NewState) |
|
- | 1037 | { |
|
- | 1038 | if( NewState==ENABLE) |
|
- | 1039 | { |
|
- | 1040 | MC->ECR |= 0x0040; |
|
- | 1041 | } |
|
- | 1042 | else |
|
- | 1043 | { |
|
- | 1044 | MC->ECR &= ~ 0x0040; |
|
- | 1045 | } |
|
- | 1046 | } |
|
- | 1047 | /******************************************************************************* |
|
- | 1048 | * Function Name : MC_DebugOutputProtection |
|
- | 1049 | * Description : Allows the output phases to follow the polarity set by PSR if |
|
- | 1050 | * enabled or they remain in their last known state if disabled. |
|
- | 1051 | * Input : NewState : This pararameter can be ENABLE or DISABLE. |
|
- | 1052 | * Output : None |
|
- | 1053 | * Return : None |
|
- | 1054 | *******************************************************************************/ |
|
- | 1055 | void MC_DebugOutputProtection(FunctionalState NewState) |
|
- | 1056 | { |
|
- | 1057 | if( NewState==ENABLE) |
|
- | 1058 | { |
|
- | 1059 | MC->ECR |= 0x0080; |
|
- | 1060 | } |
|
- | 1061 | else |
|
- | 1062 | { |
|
- | 1063 | MC->ECR &= ~0x0080; |
|
- | 1064 | } |
|
- | 1065 | } |
|
- | 1066 | ||
- | 1067 | /******************************************************************************* |
|
- | 1068 | * Function Name : MC_EmergencyStopPolarity |
|
- | 1069 | * Description : Enables or disables an Enhanced Stop Polarity feature. |
|
- | 1070 | * Input : NewState : This pararameter can be ENABLE or DISABLE. |
|
- | 1071 | * Output : None |
|
- | 1072 | * Return : None |
|
- | 1073 | *******************************************************************************/ |
|
- | 1074 | void MC_EmergencyStopPolarity(FunctionalState NewState) |
|
- | 1075 | { |
|
- | 1076 | if( NewState==ENABLE) |
|
- | 1077 | { |
|
- | 1078 | MC->ECR |= 0x0002; |
|
- | 1079 | } |
|
- | 1080 | else |
|
- | 1081 | { |
|
- | 1082 | MC->ECR &= ~0x0002; |
|
- | 1083 | } |
|
932 | 1084 | } |