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