• slider image 442
  • slider image 483
  • slider image 484
  • slider image 485
  • slider image 486
  • slider image 487
:::


Browsing this Thread:   1 Anonymous Users






Re: 請教一個關於C code問題
#8
版主
版主


查看用戶資訊
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

這段程式是使用 8MHz 振盪頻率時會延遲 12.5uS 的正半週,再延遲 12.5uS 的負半週,這樣就可以的到 25uS (40KHz) 的超音波輸出。

goto $+1 是指PIC16F時的用法,$ 是指 PC 目前的位址,所以 GOTO $ 就是永遠跳再這一行,而 goto $+1 就是指跳下一行,這樣可以用兩個 NOP 指令代替,只是用 GOTO $+1 比較節省程式空間。

goto 使用到兩個指令週期。所以是 1uS (0.5us x 2)

發表於: 2009/4/6 15:20
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教一個關於C code問題
#7
新會員
新會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教一個關於C code問題
#6
初級會員
初級會員


查看用戶資訊
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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教一個關於C code問題
#5
版主
版主


查看用戶資訊
感謝 Yiming 提供的方法。

發表於: 2009/4/6 11:10
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教一個關於C code問題
#4
資深會員
資深會員


查看用戶資訊
你用超音波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
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教一個關於C code問題
#3
初級會員
初級會員


查看用戶資訊
Hello 版主,

謝謝你的回覆.

我目前的狀況是,我的兩個PWM channel 都已經在使用了.
沒辦法空出來做這個動作. 不知道是不是有辦法只用一般的I/O pin 腳去做呢??? 如果可以該怎麼做去量測他的反射時間跟該用什麼抓這訊號呢???

我用的是 PIC 16F877 跟 CCS C compiler.

請各位前輩高手指點一下



在此先說聲謝謝了

發表於: 2009/4/5 10:30
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


Re: 請教一個關於C code問題
#2
版主
版主


查看用戶資訊
我是使用 PWM 的輸出約40KHz 的頻率每次測量只送出三個超音波脈衝後就啟動 Capture 來量測他的反射波時間。超音波不可連續送,一次測量只要送出三個 Pulse 就可以了。

發表於: 2009/4/4 15:08
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部


請教一個關於C code問題
#1
初級會員
初級會員


查看用戶資訊
Hello 大家好,

我想請教一個關於 CCS C 的問題.
我使用的是 PIC 16F877
我最近想要用Ultrasonic sensor來取代我原本的IR sensor 來測距.
可是Ultrasonic sensor好像是需要算每一個pulse的width.

有誰可以指導一下該如何計算嗎?或是該程式該如何寫嗎?



謝謝幫忙



Brian

發表於: 2009/4/4 1:47
Twitter Facebook Google Plus Linkedin Del.icio.us Digg Reddit Mr. Wong 頂部







You can view topic.
不可以 發起新主題
You cannot reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You cannot post without approval.
You cannot use topic type.
You cannot use HTML syntax.
You cannot use signature.
You cannot create PDF files.
You cannot get print page.

[進階搜尋]


:::

Microchip連結

https://www.facebook.com/microchiptechnologytaiwan/
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=13
https://mu.microchip.com/page/tmu
http://elearning.microchip.com.tw/modules/tad_link/index.php?cate_sn=1
https://page.microchip.com/APAC-PrefCenters-TW.html
http://www.microchip.com/
http://www.microchip.com/treelink
http://www.microchipdirect.com/
http://www.microchip.com.cn/newcommunity/index.php?m=Video&a=index&id=103
http://www.microchip.com.tw/modules/tad_uploader/index.php?of_cat_sn=2
http://www.microchip.com.tw/Data_CD/eLearning/index.html
http://www.microchip.com.tw/RTC/RTC_DVD/
https://www.microchip.com/development-tools/
https://www.youtube.com/user/MicrochipTechnology
[ more... ]

教育訓練中心

!開發工具購買
辦法說明 [業界客戶] [教育單位]
----------------------------------
!校園樣品申請
辦法說明 [教師資格] [學生資格]
----------------------------------