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