Re: 請教一個關於C code問題
|
||||
---|---|---|---|---|
新會員
|
Yiming大的寫法是8MHz來算的,所以一個instruction cycle=4/8Mhz=0.5us (micro-second)
"GOTO $+1 ;2 CLK 1 US ==>這是什麼意思呀? " GOTO $+1 這個意思是說PC Counter指到下一個指令去 2 CLK =>這個GOTO指令需要兩個instruction cycle,所以每執行一次要2*0.5us=1us 1 US => 1us (micro-second),這個只想要表達目前程式已經延遲了多少的時間 GOTO $+1 ;2 CLK 1 US //程式執行完後,花了1us GOTO $+1 ;2 CLK 2 US //程式執行完後,花了2us GOTO $+1 ;2 CLK 3 US //程式執行完後,花了3us GOTO $+1 ;2 CLK 4 US //程式執行完後,花了4us : : "NOP ;1 CLK 12.5US==>這是什麼意思呀?" NOP =>No Operation =>就是什麼是也沒做 1 CLK =>這個指令需要一個instruction cycle,所以每執行一次要1*0.5us=0.5us 執行到這,MCU總共花了12.5us
發表於: 2009/4/6 14:56
|
|||
|
Re: 請教一個關於C code問題
|
||||
---|---|---|---|---|
初級會員
|
Hello,
謝謝 Yiming 熱心回答.我不過很遜,組語我看不懂. GOTO $+1 ;2 CLK 1 US ==>這是什麼意思呀? NOP ;1 CLK 12.5US==>這是什麼意思呀? 如果你願意 可不可以 幫我解釋一下你寫的組語的議斯呢? 而如果high 12.5 uS low 12.5 uS. 那好像只算到12 uS而已. 後面那個0.5呢??? 我用的是 Ping))) Utrasonic sensor 其資料如下: * 3-pin interface (power, ground, signal) * 20 mA power consumption * Narrow acceptance angle * Simple pulse in / pulse out communication * Indicator LED shows measurement in progress * Input Trigger - positive TTL pulse, 2 µs min, 5 µs typ. * Echo Pulse - positive TTL pulse, 115 µs to 18.5 ms * Echo Hold-off - 750 µs from fall of Trigger pulse * Burst Frequency - 40 kHz for 200 µs datasheet 說你要是給一個 trigger pulse, 他就會回傳一個echo time pulse, 我卻不知道該怎麼抓這一個 echo time pulese. 我在網路上找資料蠻多人也是像版主說的用 PWM 可是我的 PWM 都給 motor 用掉了.所以我在想有沒有其他方式用 C來寫. 請各位高手前輩指點迷津一下. 在這裡先說聲謝謝了
發表於: 2009/4/6 13:44
|
|||
|
Re: 請教一個關於C code問題
|
||||
---|---|---|---|---|
版主
|
感謝 Yiming 提供的方法。
發表於: 2009/4/6 11:10
|
|||
|
Re: 請教一個關於C code問題
|
||||
---|---|---|---|---|
資深會員
|
你用超音波sensor是要做什麼功能,計算距離嗎?
超音波sensor比較常用的是40Khz,也就是說週期是25us hi 12.5us lo 12.5us 以PIC來說至少要用8M振盪才能做到. 除了用PWM來送比較準確之外,也可以用土法練鋼直接用IO來送時間就要自己算的很仔細了用示波器來量測. 用c語言算時間沒那麼準,inline 組合語言試試吧 BSF PORTB,0 GOTO $+1 ;2 CLK 1 US GOTO $+1 ;2 CLK 2 US GOTO $+1 ;2 CLK 3 US GOTO $+1 ;2 CLK 4 US GOTO $+1 ;2 CLK 5 US GOTO $+1 ;2 CLK 6 US GOTO $+1 ;2 CLK 7 US GOTO $+1 ;2 CLK 8 US GOTO $+1 ;2 CLK 9 US GOTO $+1 ;2 CLK 10 US GOTO $+1 ;2 CLK 11 US GOTO $+1 ;2 CLK 12 US NOP ;1 CLK 12.5US BCF PORTB,0 GOTO $+1 ;2 CLK 1 US GOTO $+1 ;2 CLK 2 US GOTO $+1 ;2 CLK 3 US GOTO $+1 ;2 CLK 4 US GOTO $+1 ;2 CLK 5 US GOTO $+1 ;2 CLK 6 US GOTO $+1 ;2 CLK 7 US GOTO $+1 ;2 CLK 8 US GOTO $+1 ;2 CLK 9 US GOTO $+1 ;2 CLK 10 US GOTO $+1 ;2 CLK 11 US GOTO $+1 ;2 CLK 12 US NOP ;1 CLK 12.5US
發表於: 2009/4/6 8:35
|
|||
|
Re: 請教一個關於C code問題
|
||||
---|---|---|---|---|
初級會員
|
Hello 版主,
謝謝你的回覆. 我目前的狀況是,我的兩個PWM channel 都已經在使用了. 沒辦法空出來做這個動作. 不知道是不是有辦法只用一般的I/O pin 腳去做呢??? 如果可以該怎麼做去量測他的反射時間跟該用什麼抓這訊號呢??? 我用的是 PIC 16F877 跟 CCS C compiler. 請各位前輩高手指點一下 在此先說聲謝謝了
發表於: 2009/4/5 10:30
|
|||
|
Re: 請教一個關於C code問題
|
||||
---|---|---|---|---|
版主
|
我是使用 PWM 的輸出約40KHz 的頻率每次測量只送出三個超音波脈衝後就啟動 Capture 來量測他的反射波時間。超音波不可連續送,一次測量只要送出三個 Pulse 就可以了。
發表於: 2009/4/4 15:08
|
|||
|
請教一個關於C code問題
|
||||
---|---|---|---|---|
初級會員
|
Hello 大家好,
我想請教一個關於 CCS C 的問題. 我使用的是 PIC 16F877 我最近想要用Ultrasonic sensor來取代我原本的IR sensor 來測距. 可是Ultrasonic sensor好像是需要算每一個pulse的width. 有誰可以指導一下該如何計算嗎?或是該程式該如何寫嗎? 謝謝幫忙 Brian
發表於: 2009/4/4 1:47
|
|||
|