亚洲伦理在线,www.黄片在线,成人熟女在线,有吗在线视频

  • <p id="sjllw"><span id="sjllw"><del id="sjllw"></del></span></p>

    <p id="sjllw"><pre id="sjllw"></pre></p>

      
      
      <i id="sjllw"></i>
      <pre id="sjllw"><label id="sjllw"><label id="sjllw"></label></label></pre>
      <p id="sjllw"><span id="sjllw"><del id="sjllw"></del></span></p><i id="sjllw"></i>
      <p id="sjllw"><span id="sjllw"><del id="sjllw"></del></span></p>

            聯(lián)系方式
            聯(lián)系人:黃小姐
            聯(lián)系電話:0755-25848978, 83738778
            傳真號(hào)碼:0755-83738639
            公司地址:深圳市寶安區(qū)西鄉(xiāng)街道寶源路深圳市名優(yōu)工業(yè)產(chǎn)品展示采購中心B座1區(qū)五樓508號(hào)
            Email:sales@sandat.com
            郵編:518102
            公司網(wǎng)址:http://www.sandat.com
            文章詳情

            SMT16030溫度傳感器與 68HC11 型單片機(jī)的連接

            日期:2025-06-26 09:21
            瀏覽次數(shù):8166
            摘要:

            SMT16030溫度傳感器 68HC11 型單片機(jī)的連接

            H. Liefting

            這個(gè)操作說明書描述了Smartec溫度傳感器如何與68HC11單片機(jī)連接。

            支持兩種輸入形式: 捕獲輸入和規(guī)則輸入。 

            A. 使用捕獲輸入

            SMARTEC溫度傳感器有一個(gè)占空因數(shù)輸出: 

                                   全周期

            為了計(jì)算占空因數(shù),必須獲得兩個(gè)測(cè)量結(jié)果。一個(gè)是一個(gè)全周期所用的時(shí)間,另一個(gè)是信號(hào)為高電平('1')的時(shí)間。兩種時(shí)間都可以使用輸入捕獲計(jì)時(shí)器來測(cè)量。

            當(dāng)輸入由邏輯'1'跳變?yōu)?/font>'0'時(shí)計(jì)時(shí)器啟動(dòng)。信號(hào)由'0''1'時(shí),存儲(chǔ)計(jì)時(shí)器中的內(nèi)容。周期末端當(dāng)信號(hào)由再次'1' '0'時(shí),再次存儲(chǔ)計(jì)時(shí)器中的內(nèi)容。現(xiàn)在我們可以計(jì)算占空因數(shù)了。

            0.5ms可以獲得一次全周期所用的時(shí)間 (t ) 和信號(hào)為高電平('1')時(shí)的時(shí)間 (t 

            利用這些時(shí)間來計(jì)算傳感器的溫度傳感器的規(guī)格書中給出了下面的公式:

             

            占空因數(shù) (d.c.)= 0.31924 + 0.00472 x 溫度 ()

            所以溫度是:211.9 x ( d.c. - 0.31924)。為了簡便,在方程兩邊乘以(65536)來出去小數(shù)部分:

            溫度 x 65536 = 211.9 x ( 2 x d.c. - 20922),

             

            309 x 溫度 = 2 x d.c. – 20922

            變量 d.c. x 2可以計(jì)算如下::信號(hào)是高電平的時(shí)間除以全周期時(shí)間。使用 'fdiv' 指令來進(jìn)行除法操作。'fdiv' 指令乘完除數(shù)2之后將劃分兩個(gè)16-bit數(shù)。這正是我們需要的。在從計(jì)算結(jié)果中減20922。之后我們獲得309*溫度。25度的溫度將產(chǎn)生一個(gè)數(shù)值25 x 309 = 7725。使用這些數(shù)可以簡化進(jìn)一步的計(jì)算。

            傳感器輸出信號(hào)頻率在1 kHz4 kHz 之間。 這表明每毫秒都能獲得一個(gè)測(cè)量值。能夠充分滿足一般需求。我們測(cè)量不止一個(gè)值,而是測(cè)量100個(gè)周期然后取平均值。

             

            *************************************************

            溫度測(cè)量

            *************************************************

            在輸入信號(hào)的still_to_do階段測(cè)量結(jié)果累加

            * -周期總數(shù)表示為periodsum

            * -信號(hào)總數(shù)中信號(hào)為'1' 的時(shí)間表示為signalsum

             

            * 在每個(gè)周期的結(jié)束時(shí),still_to_do低于電平1

            如果保持信號(hào)still_to_do降為零測(cè)量完成求和將不再增加

            經(jīng)過一段時(shí)間調(diào)整,'meas_on' 標(biāo)志位將被重置

             

            開始測(cè)量:

            * - 'meas_on' 標(biāo)志位必須設(shè)置為 '1'

            * -在測(cè)量過程中,必須用測(cè)量的平均周期數(shù)來初始化'still_to_do' *       

            * - 周期總數(shù)和信號(hào)總數(shù)必須設(shè)為0

            程序段

             

            溫度測(cè)量的數(shù)據(jù)區(qū)

            DATA    space

            still_to_do       rmb 1          |number of periods to accumulate

            meas_on         rmb 1          |flag to indicate the measurement is running

            periodsum        rmb 3          |accumulates period times

            signalsum        rmb 3          |accumulates '1' time of the signal

             

            存儲(chǔ)以便內(nèi)部應(yīng)用

            periodstart    rmb 2           |startingtime of a period

            starttime1      rmb 2           |time at which the signal became '1'

             

            溫度測(cè)量初始化

            程序段

                            clr meas_on

                            clr still_to_do  |no measurement active

                            ldab #$7E        |initialize the interrupt vector

                            stab tic1int

                            ldd #sensorint

                            std tic1int+1

                            ldx #regsbeg    |start measuring a falling edge

                            bclr tctl2-regsbeg,x,edg1a

                            bset tctl2-regsbeg,x,edg1b

                            ldab #ic1f       clear possibly pending interrupt

                            stab tflg1-regsbeg,x

                            bset tmsk1-regsbeg,x,ic1i

            jmp tempend     |end of the initialization

             

             

            溫度測(cè)量子程序

            程序段

            *******輸入中斷程序 *******

            sensorint       equ $

                            ldx #regsbeg    |let IX point at the I/O registers

            **次設(shè)置中斷標(biāo)志位

                            ldab #ic1f

                            stab tflg1-regsbeg,x

            確定是上升沿還是下降沿

                            brclr tctl2-regsbeg,x,edg1a,sensorint1

             

            *如果是上升沿我們是在測(cè)量中間階段

            記錄下上升沿時(shí)間

                            ldd tic1-regsbeg,x

                            std starttime1

            等待下降沿

                            bclr tctl2-regsbeg,x,edg1a

                            bset tctl2-regsbeg,x,edg1b

                            bra sensorint9

            如果處于下降沿,我們處于周期的結(jié)束

            一個(gè)周期的結(jié)束同時(shí)也是另一個(gè)周期的開始

            sensorint1      equ $

                            tst meas_on      |check if the measurement should be taken

                            beq sensorint4

            當(dāng)進(jìn)行測(cè)量的時(shí)候

            累計(jì)信號(hào)為“1”的總時(shí)間

                            ldd tic1-regsbeg,x

                            subd starttime1

                            addd signalsum+1

                            std signalsum+1

                            ldaa signalsum

                            adca #0

                            staa signalsum

            存儲(chǔ)總的周期時(shí)間

                            ldd tic1-regsbeg,x

                            subd periodstart

                            addd periodsum+1

                            std periodsum+1

                            ldaa periodsum

                           adca #0

                            staa periodsum

            * one more period done, one less to do

                            dec still_to_do

                            bne sensorint4

            *如果需要測(cè)量更多的周期,測(cè)量是準(zhǔn)備好的

                            clr meas_on

            記錄下新的周期開始的時(shí)間

            sensorint4      ldd tic1-regsbeg,x

                            std periodstart

            等待一個(gè)上升沿

                            bset tctl2-regsbeg,x,edg1a

                            bclr tctl2-regsbeg,x,edg1b

            sensorint9      rti

             

            開始測(cè)量100個(gè)周期

            startmeas       equ $

                            tpa              |save the condition-code register on the stack

                            psha             |(using A)

                            sei              |temporarily block the interrupts

                            ldaa #100

                            staa still_to_do

                            ldd #0

                            std periodsum   |clear the results

                            staa periodsum+2

                            std signalsum

                            staa signalsum+2

                            ldab #1          |start the measurement

                            stab meas_on

                            pula             |retrieve the condition-code register

                            tap              |from the stack (using A)

                           rts

            ***** 主程序的應(yīng)用程序

            程序段

            測(cè)量溫度,并將結(jié)果放在D中。結(jié)果表示為攝氏溫度* 309的數(shù)值

            grad            equ 309

            meas_temp    equ $

                            pshx             |save IX on the stack

                            bsr startmeas    |start a measurement of 256 periods

            meas_temp0    tst meas_on      |wait until the measurement is ready

                            bne meas_temp0

            mess_temp1     ldab periodsum  |scale both times back to values that

                            orab signalsum  |will fit in 16 bits

                            beq meas_temp2   |do this by dividing both values by 2

                            lsr periodsum    |until both are within the 16-bit range

                            ror periodsum+1

                            ror periodsum+2

                            lsr signalsum

                            ror signalsum+1

                            ror signalsum+2

                            bra mess_temp1

             

            meas_temp2    ldx periodsum+1

                            ldd signalsum+1

                            fdiv            |calculate the duty-cycle

                            xgdx             |put the result into D

                           subd #20922    |then correct (see explanation in handbook)

                           pulx             |retrieve IX from the stack

                           rts

            B. 使用規(guī)則輸入信號(hào)

            輸入捕獲計(jì)時(shí)器是SMARTEC溫度傳感器的優(yōu)選輸入。但.SMARTEC傳感器也能夠和規(guī)則輸入連接。程序要對(duì)輸入進(jìn)行掃描,然后確定掃描信號(hào)的信號(hào)/周期比率。這要通過積累抽樣次數(shù)、信號(hào)為“1“的次數(shù)、然后用后面的除以前面的。

            使用這種方法時(shí),要考慮以下幾點(diǎn)。

            測(cè)量結(jié)果的分辨率由用來計(jì)算占空因數(shù)的抽樣數(shù)目來決定。由于掃描處理很緩慢,在一個(gè)合理的時(shí)間內(nèi)不可能積累大量的抽樣信號(hào)。小數(shù)量的抽樣將取得一個(gè)不太**的占空因數(shù)和溫度。多次的掃描可以得到大量的抽樣。但是在這樣的情況下,測(cè)量值對(duì)溫度的響應(yīng)不夠好。

            記住非常重要的一點(diǎn),傳感器信號(hào)與抽樣處理之間完全沒有聯(lián)系。如果傳感器信號(hào)頻率是(或是整數(shù)倍的)等于掃描信號(hào)頻率,你會(huì)得到一個(gè)錯(cuò)誤的結(jié)果。注意:傳感器信號(hào)頻率隨溫度變化很大。確保掃描是在傳感器信號(hào)周期內(nèi)隨機(jī)進(jìn)行的。

            下面的編碼可以由主程序調(diào)用來測(cè)量溫度。在這個(gè)例子中假定測(cè)量程序作為主掃描循環(huán)的一部分,以固定間隔被調(diào)用。為了確保測(cè)量程序是在smartecs周期內(nèi)的隨機(jī)時(shí)間被調(diào)用,測(cè)量程序中引入了一個(gè)隨機(jī)延遲。如果你能保證測(cè)量程序是隨機(jī)被訪問的,也可以不引入隨機(jī)延遲。測(cè)量值來自所有測(cè)量結(jié)果的累計(jì),所以溫度的讀數(shù)將是相對(duì)大的數(shù)量取樣的平均,也不會(huì)對(duì)溫度的改變迅速響應(yīng)。如果需要快速檢測(cè)溫度變化,那么不要累計(jì)測(cè)量結(jié)果,但要在每次測(cè)量前清空累加器。

            *************************************************

            *大長度隨機(jī)發(fā)生器

            *************************************************

            隨機(jī)發(fā)生器由一個(gè)7位的移位寄存器實(shí)現(xiàn),此移位寄存器的bit5和bit6異或后反饋給bit0.

            DATA            space

            seed            rmb 1            |the shift register's seed

            PROGRAM         space

            ** 初始化

                             ldaa #1

                             staa seed        |init. the register to anything but 0

                             jmp randomend

            ******* get a random number (1..127) from the generator into (B)

            getrandom      equ $

                             ldab seed        |get current seed

                             aslb             |shift left to XOR bit6 with bit5

                             eorb seed

                             aslb

                             aslb             |resulting bit is now in the carry flag

                             rol seed         |rotate new bit into shift register

                             ldab seed      |get the new random number

                             andb #$7F

                             rts

            randomend      equ $

             

                   

            *************************************************

            溫度測(cè)量

            *************************************************

            多次累計(jì)

            * - 在periodsum中有多少個(gè)取樣

            * - 在signalsum中為1的信號(hào)數(shù)

            任何時(shí)候兩個(gè)累加器中的值都超過 65535 (16 bits) ,兩個(gè)寄存器中的值都除以2.

            程序段

            tempstart       equ $            |the starting address of this module

            溫度測(cè)量數(shù)據(jù)區(qū)

            DATA            space

            periodsum      rmb 3           |counts samples taken

            signalsum       rmb 3          |counts samples valued '1'

            溫度測(cè)量初始化

            PROGRAM     space

                            ldd #0

                            std periodsum   |clear the counters

                            staa periodsum+2

                            std signalsum

                            staa signalsum+2

                            jmp tempend     |end of the initialization

            *溫度測(cè)量的子程序

            程序段

            ******* 從傳感器取一次樣

            take_sample   equ $

                            ldab porta       |get the signal into bit0 of accumulator (B)

            asrb

            asrb

            andb #bit0      |mask out only the smartec signal

            clra             |add sample to accumulator

            addd signalsum+1

            std signalsum+1

            ldaa signalsum

            adca #0

            staa signalsum

            ldd #1           |add one more sample to the sample coun

            addd periodsum+1

            std periodsum+1

            ldaa periodsum

            adca #0

            staa periodsum

            rts

            *******從傳感器連續(xù)多次取樣

            ******* 取樣次數(shù)放入 (B)

            take_samples  equ $

                            pshb             |take the required number of samples

                            bsr take_sample

                            pulb

                            decb

                            bne take_samples

            take_samples0 ldab periodsum  |scale both accumulators back to values that

                            orab signalsum   |will fit in 16 bits

                            beq take_samps9  |do this by dividing both values by 2

                            lsr periodsum  |until both are within the 16-bit range

                           ror periodsum+1

                           ror periodsum+2

                            lsr signalsum

                            ror signalsum+1

                            ror signalsum+2

                            bra take_samples0

            take_samps9    rts

             

            溫度測(cè)量結(jié)果放在 D結(jié)果是

            度數(shù) (攝氏的溫度) * 309

            meas_temp    equ $

                            pshx

                            jsr getrandom   |get a random number into (B)

            meas_temp0    decb             |and use that to generate a random delay

                            bne meas_temp0

                            ldab #50

                            bsr take_samples

                            ldx periodsum+1

                            ldd signalsum+1

                            fdiv             |calculate the duty-cycle

                            xgdx             |put the result into D

                            subd #20922    |then correct (see explanation in handbook)

                            pulx             |retrieve IX from the stack

                            rts

            tempend         equ $            |end of this module

            * the number of bytes this module requires in the PROGRAM area

            tempsize        equ tempend-tempstart

            粵公網(wǎng)安備 44030602001744號(hào)