📄 stm32f10x_tim.lst
字号:
646 * - TIM_ExtTRGPSC_DIV8.
647 * - TIM_ExtTRGPolarity: The external Trigger Polarity.
648 * It can be one of the following values:
649 * - TIM_ExtTRGPolarity_Inverted
650 * - TIM_ExtTRGPolarity_NonInverted
651 * - ExtTRGFilter: External Trigger Filter.
652 * This parameter must be a value between 0x00 and 0x0F
653 * Output : None
654 * Return : None
655 *******************************************************************************/
656 void TIM_ETRClockMode1Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, u16 TIM_ExtTRGPolarity,
657 u8 ExtTRGFilter)
658 {
659 /* Check the parameters */
660 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
661 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
662
663 /* Configure the ETR Clock source */
664 TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
665
666 /* Select the External clock mode1 */
667 TIMx->SMCR &= SMCR_SMS_Mask;
668 TIMx->SMCR |= TIM_SlaveMode_External1;
669
670 /* Select the Trigger selection : ETRF */
671 TIMx->SMCR &= SMCR_TS_Mask;
672 TIMx->SMCR |= TIM_TS_ETRF;
673 }
674
675 /*******************************************************************************
676 * Function Name : TIM_ETRClockMode2Config
677 * Description : Configures the External clock Mode2
678 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
679 * - TIM_ExtTRGPrescaler: The external Trigger Prescaler.
680 * It can be one of the following values:
681 * - TIM_ExtTRGPSC_OFF
682 * - TIM_ExtTRGPSC_DIV2
683 * - TIM_ExtTRGPSC_DIV4
684 * - TIM_ExtTRGPSC_DIV8
685 * - TIM_ExtTRGPolarity: The external Trigger Polarity.
686 * It can be one of the following values:
687 * - TIM_ExtTRGPolarity_Inverted
688 * - TIM_ExtTRGPolarity_NonInverted
689 * - ExtTRGFilter: External Trigger Filter.
690 * This parameter must be a value between 0x00 and 0x0F
691 * Output : None
692 * Return : None
693 *******************************************************************************/
694 void TIM_ETRClockMode2Config(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler,
695 u16 TIM_ExtTRGPolarity, u8 ExtTRGFilter)
696 {
697 /* Check the parameters */
698 assert_param(IS_TIM_EXT_PRESCALER(TIM_ExtTRGPrescaler));
699 assert_param(IS_TIM_EXT_POLARITY(TIM_ExtTRGPolarity));
700
701 /* Configure the ETR Clock source */
702 TIM_ETRConfig(TIMx, TIM_ExtTRGPrescaler, TIM_ExtTRGPolarity, ExtTRGFilter);
703
704 /* Enable the External clock mode2 */
705 TIMx->SMCR |= SMCR_ECE_Set;
706 }
707
708 /*******************************************************************************
709 * Function Name : TIM_ETRConfig
710 * Description : Configures the TIMx External Trigger (ETR).
711 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
712 * - TIM_ExtTRGPrescaler: The external Trigger Prescaler.
713 * This parameter can be one of the following values:
714 * - TIM_ExtTRGPSC_OFF
715 * - TIM_ExtTRGPSC_DIV2
716 * - TIM_ExtTRGPSC_DIV4
717 * - TIM_ExtTRGPSC_DIV8
718 * - TIM_ExtTRGPolarity: The external Trigger Polarity.
719 * This parameter can be one of the following values:
720 * - TIM_ExtTRGPolarity_Inverted
721 * - TIM_ExtTRGPolarity_NonInverted
722 * - ExtTRGFilter: External Trigger Filter.
723 * This parameter must be a value between 0x00 and 0x0F.
724 * Output : None
725 * Return : None
726 *******************************************************************************/
727 void TIM_ETRConfig(TIM_TypeDef* TIMx, u16 TIM_ExtTRGPrescaler, u16 TIM_ExtTRGPolarity,
728 u8 ExtTRGFilter)
729 {
730 u32 tmpsmcr = 0;
731
732 tmpsmcr = TIMx->SMCR;
733
734 /* Set the Prescaler, the Filter value and the Polarity */
735 tmpsmcr &= SMCR_ETR_Mask;
736 tmpsmcr |= TIM_ExtTRGPrescaler | TIM_ExtTRGPolarity | (u16)((u16)ExtTRGFilter << 8);
737
738 TIMx->SMCR = (u16)tmpsmcr;
739 }
740
741 /*******************************************************************************
742 * Function Name : TIM_SelectInputTrigger
743 * Description : Selects the Input Trigger source
744 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
745 * - TIM_InputTriggerSource: The Input Trigger source.
746 * This parameter can be one of the following values:
747 * - TIM_TS_ITR0: Internal Trigger 0
748 * - TIM_TS_ITR1: Internal Trigger 1
749 * - TIM_TS_ITR2: Internal Trigger 2
750 * - TIM_TS_ITR3: Internal Trigger 3
751 * - TIM_TS_TI1F_ED: TI1 Edge Detector
752 * - TIM_TS_TI1FP1: Filtered Timer Input 1
753 * - TIM_TS_TI2FP2: Filtered Timer Input 2
754 * - TIM_TS_ETRF: External Trigger input
755 * Output : None
756 * Return : None
757 *******************************************************************************/
758 void TIM_SelectInputTrigger(TIM_TypeDef* TIMx, u16 TIM_InputTriggerSource)
759 {
760 u32 tmpsmcr = 0;
761
762 /* Check the parameters */
763 assert_param(IS_TIM_TRIGGER_SELECTION(TIM_InputTriggerSource));
764
765 tmpsmcr = TIMx->SMCR;
766
767 /* Select the Tgigger Source */
768 tmpsmcr &= SMCR_TS_Mask;
769 tmpsmcr |= TIM_InputTriggerSource;
770
771 TIMx->SMCR = (u16)tmpsmcr;
772 }
773
774 /*******************************************************************************
775 * Function Name : TIM_PrescalerConfig
776 * Description : Configures the TIMx Prescaler.
777 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
778 * - Prescaler: specifies the Prescaler Register value
779 * - TIM_PSCReloadMode: specifies the TIM Prescaler Reload mode
780 * This parameter can be one of the following values:
781 * - TIM_PSCReloadMode_Update: The Prescaler is loaded at
782 * the update event.
783 * - TIM_PSCReloadMode_Immediate: The Prescaler is loaded
784 * immediatly.
785 * Output : None
786 * Return : None
787 *******************************************************************************/
788 void TIM_PrescalerConfig(TIM_TypeDef* TIMx, u16 Prescaler, u16 TIM_PSCReloadMode)
789 {
790 /* Check the parameters */
791 assert_param(IS_TIM_PRESCALER_RELOAD(TIM_PSCReloadMode));
792
793 /* Set the Prescaler value */
794 TIMx->PSC = Prescaler;
795
796 /* Set or reset the UG Bit */
797 if (TIM_PSCReloadMode == TIM_PSCReloadMode_Immediate)
798 {
799 TIMx->EGR |= TIM_EventSource_Update;
800 }
801 else
802 {
803 TIMx->EGR &= TIM_EventSource_Update;
804 }
805 }
806
807 /*******************************************************************************
808 * Function Name : TIM_CounterModeConfig
809 * Description : Specifies the TIMx Counter Mode to be used.
810 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
811 * - TIM_CounterMode: specifies the Counter Mode to be used
812 * This parameter can be one of the following values:
813 * - TIM_CounterMode_Up: TIM Up Counting Mode
814 * - TIM_CounterMode_Down: TIM Down Counting Mode
815 * - TIM_CounterMode_CenterAligned1: TIM Center Aligned Mode1
816 * - TIM_CounterMode_CenterAligned2: TIM Center Aligned Mode2
817 * - TIM_CounterMode_CenterAligned3: TIM Center Aligned Mode3
818 * Output : None
819 * Return : None
820 *******************************************************************************/
821 void TIM_CounterModeConfig(TIM_TypeDef* TIMx, u16 TIM_CounterMode)
822 {
823 u32 tmpcr1 = 0;
824
825 /* Check the parameters */
826 assert_param(IS_TIM_COUNTER_MODE(TIM_CounterMode));
827
828 tmpcr1 = TIMx->CR1;
829
830 /* Reset the CMS and DIR Bits */
831 tmpcr1 &= CR1_CounterMode_Mask;
832
833 /* Set the Counter Mode */
834 tmpcr1 |= TIM_CounterMode;
835
836 TIMx->CR1 = (u16)tmpcr1;
837 }
838
839 /*******************************************************************************
840 * Function Name : TIM_ForcedOC1Config
841 * Description : Forces the TIMx output 1 waveform to active or inactive level.
842 * Input : - TIMx: where x can be 2, 3 or 4 to select the TIM peripheral.
843 * - TIM_ForcedAction: specifies the forced Action to be set to
844 * the output waveform.
845 * This parameter can be one of the following values:
846 * - TIM_ForcedAction_Active: Force active level on OC1REF
847 * - TIM_ForcedAction_InActive: Force inactive level on
848 * OC1REF.
849 * Output : None
850 * Return : None
851 *******************************************************************************/
852 void TIM_ForcedOC1Config(TIM_TypeDef* TIMx, u16 TIM_ForcedAction)
853 {
854 u32 tmpccmr1 = 0;
855
856 /* Check the parameters */
857 assert_param(IS_TIM_FORCED_ACTION(TIM_ForcedAction));
858
859 tmpccmr1 = TIMx->CCMR1;
860
861 /* Reset the OCM Bits */
862 tmpccmr1 &= CCMR_OCM13_Mask;
863
864 /* Configure The Forced output Mode */
865 tmpccmr1 |= TIM_ForcedAction;
866
867 TIMx->CCMR1 = (u16)tmpccmr1;
868 }
869
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -