stm32 霍爾傳感器接口
使用高級(jí)控制定時(shí)器(TIM1或TIM8)產(chǎn)生PWM信號(hào)驅(qū)動(dòng)馬達(dá)時(shí),可以用另一個(gè)通用TIMx(TIM2、TIM3、TIM4或TIM5)定時(shí)器作為“接口定時(shí)器”來連接霍爾傳感器,見圖93,3個(gè)定時(shí)器輸入腳(CC1、CC2、CC3)通過一個(gè)異或門連接到TI1輸入通道(通過設(shè)置TIMx_CR2寄存器中的TI1S位來選擇),“接口定時(shí)器”捕獲這個(gè)信號(hào)。
本文引用地址:http://m.butianyuan.cn/article/201611/315856.htm從模式控制器被配置于復(fù)位模式,從輸入是TI1F_ED。每當(dāng)3個(gè)輸入之一變化時(shí),計(jì)數(shù)器從新從0開始計(jì)數(shù)。這樣產(chǎn)生一個(gè)由霍爾輸入端的任何變化而觸發(fā)的時(shí)間基準(zhǔn)。 “接口定時(shí)器”上的捕獲/比較通道1配置為捕獲模式,捕獲信號(hào)為TRC(見圖76)。捕獲值反映了兩個(gè)輸入變化間的時(shí)間延遲,給出了馬達(dá)速度的信息。 “接口定時(shí)器”可以用來在輸出模式產(chǎn)生一個(gè)脈沖,這個(gè)脈沖可以(通過觸發(fā)一個(gè)COM事件)用于改變高級(jí)定時(shí)器TIM1或TIM8各個(gè)通道的屬性,而高級(jí)控制定時(shí)器產(chǎn)生PWM信號(hào)驅(qū)動(dòng)馬達(dá)。因此“接口定時(shí)器”通道必須編程為在一個(gè)指定的延時(shí)(輸出比較或PWM模式)之后產(chǎn)生一個(gè)正脈沖,這個(gè)脈沖通過TRGO輸出被送到高級(jí)控制定時(shí)器TIM1或TIM8。 舉例:霍爾輸入連接到TIMx定時(shí)器,要求每次任一霍爾輸入上發(fā)生變化之后的一個(gè)指定的時(shí)刻,改變高級(jí)控制定時(shí)器TIMx的PWM配置。
● 置TIMx_CR2寄存器的TI1S位為’1’,配置三個(gè)定時(shí)器輸入邏輯或到TI1輸入,
● 時(shí)基編程:置TIMx_ARR為其最大值(計(jì)數(shù)器必須通過TI1的變化清零)。設(shè)置預(yù)分頻器得到一個(gè)最大的計(jì)數(shù)器周期,它長于傳感器上的兩次變化的時(shí)間間隔。
● 設(shè)置通道1為捕獲模式(選中TRC):置TIMx_CCMR1寄存器中CC1S=01,如果需要,還可以設(shè)置數(shù)字濾波器。
● 設(shè)置通道2為PWM2模式,并具有要求的延時(shí):置TIMx_CCMR1寄存器中的OC2M=111和CC2S=00。
● 選擇OC2REF作為TRGO上的觸發(fā)輸出:置TIMx_CR2寄存器中的MMS=101。 在高級(jí)控制寄存器TIM1中,正確的ITR輸入必須是觸發(fā)器輸入,定時(shí)器被編程為產(chǎn)生PWM信號(hào),捕獲/比較控制信號(hào)為預(yù)裝載的(TIMx_CR2寄存器中CCPC=1),同時(shí)觸發(fā)輸入控制COM事件(TIMx_CR2寄存器中CCUS=1)。在一次COM事件后,寫入下一步的PWM控制位(CCxE、OCxM),這可以在處理OC2REF上升沿的中斷子程序里實(shí)現(xiàn)。 下圖顯示了這個(gè)實(shí)例
無刷電機(jī)每運(yùn)行一圈,霍爾有六個(gè)狀態(tài),在每個(gè)狀態(tài)均會(huì)進(jìn)入一次中斷,
正常運(yùn)轉(zhuǎn)的時(shí)候電機(jī)是按照1,3,2,6,4,5
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=3764371&bbs_page_no=1&search_mode=1&search_text=hall&bbs_id=3020
Setting up the system when using Hall-effect sensors
Hall-effect sensors are devices capable of sensing the polarity of the rotor’s magnetic field;
they provide a logic output, which is 0 or 1 depending on the magnetic pole they face and
thus, on the rotor position.
Typically, in a three-phase PM motor three Hall-effect sensors are used to feed back the
rotor position information. They are usually mechanically displaced by either 120° or 60° and
the presented firmware library was designed to support both possibilities. To set up the
PMSM FOC software library for use with three Hall sensors, simply modify the
stm32f10x_MCconf.h and MC_hall_param.h header files according to the indications given
in Section 4.1 and Section 4.4, respectively.
As shown in Figure 30, the typical waveforms can be visualized at the sensor outputs in
case of 60° and 120° displaced Hall sensors. More particularly, Figure 30 refers to an
electrical period (i.e. one mechanical revolution in case of one pole pair motor).
Figure 30. 60° and 120° displaced Hall sensor output waveforms
Since the rotor position information they provide is absolute, there is no need for any initial
rotor prepositioning. Particular attention must be paid, however, when connecting the
sensors to the proper microcontroller inputs.
In fact, as stated in Section 3.11, this software library assumes that the positive rolling
direction is the rolling direction of a machine that is fed with a three-phase system of positive
sequence. In that case to properly work, the software library expects the Hall sensor signal
transitions to be in the sequence shown in Figure 30 for both 60° and 120° displaced Hall
sensors.
For these reasons, it is suggested to follow the instructions given below when connecting a
Hall-sensor equipped PM motor to your board:
1. Turn the rotor by hand in the direction assumed to be positive and look at the B-emf
induced on the three motor phases. For this purpose if the real neutral point is not
available, it can be reconstructed by means of three resistors for instance.
2. Connect the motor phases to the hardware respecting the positive sequence. Let
“Phase A”, “Phase B” and “Phase C” be the motor phases driven by TIM1_CH1,
TIM1_CH2 and TIM1_CH3, respectively (e.g. when using the MB459 board, a positive
sequence of the motor phases could be connected to J5 2,1 and 3).
3. Turn the rotor by hand in the direction assumed to be positive, look at the three Hall
sensor outputs (H1, H2 and H3) and connect them to the selected timer on channels 1,
2 and 3, respectively, making sure that the sequence shown in Figure 30 is respected.
4. Measure the delay in electrical degrees betweenthe maximum of the B-emf induced on
Phase Aandthe first rising edge of signal H1. Enter it in the MC_hall_param.h header
file (HALL_PHASE_SHIFT). For your convenience, an example with
HALL_PHASE_SHIFT equal to –90 °C is illustrated in Figure 31.
評(píng)論