日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導讀]使用stm32cubemx配置外設,代碼使用HAL stm32f1 v1.3.1庫。用的是stm32l152c開發(fā)板,時鐘頻率32MHZ。這里,沒有配置中斷。上圖的意思是,TI2收到1給正脈沖,觸發(fā)TIM1開始計數(shù),經(jīng)過 tDelay后,OC1輸出低,經(jīng)過一個tP

使用stm32cubemx配置外設,代碼使用HAL stm32f1 v1.3.1庫。

用的是stm32l152c開發(fā)板,時鐘頻率32MHZ。





這里,沒有配置中斷。



上圖的意思是,TI2收到1給正脈沖,觸發(fā)TIM1開始計數(shù),經(jīng)過 tDelay后,OC1輸出低,經(jīng)過一個tPulse后,OC1又恢復為高。


The OPM waveform is defined by writing the compare registers (taking into account theclock frequency and the counter prescaler).
? The tDELAY is defined by the value written in the TIMx_CCR1 register.
? The tPULSEis defined by the difference between the auto-reload value and the comparevalue (TIMx_ARR - TIMx_CCR + 1).

Let’s say you want to build a waveform with a transition from ‘0 to ‘1 when a comparematch occurs and a transition from ‘1 to ‘0 when the counter reaches the auto-reloadvalue.

To do this you enable PWM mode 2 by writing OC1M=111 in the TIMx_CCMR1register. You can optionally enable the preload registers by writing OC1PE=1 in the
TIMx_CCMR1 register and ARPE in the TIMx_CR1 register. In thiscase you have towrite the compare value in the TIMx_CCR1 register, the auto-reload value in the
TIMx_ARR register, generate an update by setting the UG bit and wait for externaltrigger event on TI2. CC1P is written to ‘0 in this example.

向比較寄存器寫入數(shù)值(考慮時鐘頻率和計數(shù)分頻來計算)來定義OPM波形。

1)tDelay值是TIMx_CCR1寄存器值

2)tPulse的值是 自動重裝值減掉比較值:(TIMx_ARR - TIMx_CCR + 1)


假如,當比較相符發(fā)生時,你希望得到從0到1的波形,而當計數(shù)器達到自動重裝值時,波形又從1變到0.

這種情況,使用PWM模式2,TIMx_CCMR1 寄存器的OC1M要為111。可選:使能重裝寄存器。 在此例子中,你需要把比較值寫到TIMx_CCR1 寄存器,自動重裝值寫到TIMx_ARR寄存器,設置UG位產(chǎn)生一個更新事件,并且等待TI2的外部觸發(fā)事件。CC1P被寫為 0.


看了手冊上面的描述,就明白了:

我按下按鈕,延時2秒,點亮綠燈,停1秒,綠燈滅。


如果是控制可控硅,就是:

檢測到零點,延時x微秒,觸發(fā)可控硅,停1毫秒,關掉可控硅。 生成觸發(fā)脈沖。

可以讓硬件自己處理,不用中斷。


開發(fā)板實現(xiàn)描述1.


while(1)

{

/*USERCODEENDWHILE*/

/*USERCODEBEGIN3*/

if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==GPIO_PIN_SET){

HAL_Delay(100);

if(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0)==GPIO_PIN_SET){

__HAL_TIM_ENABLE(&htim4);

HAL_TIM_OnePulse_Start(&htim4,TIM_CHANNEL_2);

}

}

}

/*USERCODEEND3*/


HAL_TIM_OnePulse_Start函數(shù)有問題,它總是使能1、2兩個通道,而且它不啟用定時器的計數(shù)。


因此,在它之前要使用宏__HAL_TIM_ENABLE,置位TIMx_CR1的CEN。


需要注意到,單脈沖功能,只能在1、2通道上做。


本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關閉