Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : New Micromite PULSIN Function
Author | Message | ||||
Goeytex Regular Member Joined: 12/05/2014 Location: United StatesPosts: 74 |
Geoff has added a PULSIN function to MMBasic for the Micromite. Pulsin can read the width of a pulse from 1us to 1 sec with a resolution of 100ns. More info can be found HERE This opens up a lot of possibilities. Below is a sample program I did to calculate period / frequency using Pulsin. With a 10kHz applied signal, accuracy is within about .5%. But the good part is that a frequency can be acquired * calculated in < 3ms instead of the 1 second needed by FIN. Of course this time will increase with slow signals. To use Pulsin you will need Micromite V4.5D (Beta) Here is the code I used for testing. CODE [code] '====================================== 'Micromite MMBasic Ver4.5D (Beta) 'Using Pulsin to get Period / Frequency '====================================== CPU 40 SetPin(15),DIN get_period: Do Timer = 0 Mark = Pulsin(15,1) '// Get Mark Space = Pulsin(15,0) '// Get Space If Mark = -1 Or Space = -1 Then GoTo err1 '// Check for error Period = Mark + Space '// Sum Frequency = 1000000 / period '// Calc Freq TT = Timer Print "Period =" period "us" Print "Frequency =" Frequency "Hz" Print "Code Execution Time: " TT "ms" mark = 0 : Space = 0 '//clear variables Pause 500 Loop err1: Print "Error" Pause 20 GoTo get_period [/code] Bill |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
Do think it may be possible to use the pulsing / pulsout on the same pin to communicate with the SRF 005 ultrasonic transducer, using one connection as is done with the picaxe. pulsout c.1,2 ' produces about 20uS pulse (must be minimum of 10uS) pulsin c.1,1,range ' measures the range in 10uS steps pause 10 ' SRF005 mandatory 10mS recharge period ' after ranging completes let range = range * 10 /58 Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6103 |
Bill, The SRF005 looks to be the same as the HC-SR04 which the microMite can talk to as is. The microMite can also use the 3 terminal versions where the trigger and echo share the same pin. You should be able to use the PULSEIN command but have you tried the SRF005 with the microMite's DISTANCE command? Jim VK7JH MMedit MMBasic Help |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
Thanks Jim No not yet as I only received my blank Pic32s yesterday. I had just finished downloading 4.6c when I read this. Will have to reprogram the chips with 4.5d and give it a try. maybe I should read the manual first. Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Goeytex Regular Member Joined: 12/05/2014 Location: United StatesPosts: 74 |
I would try it with both the Distance command and with Pulsin and see which works better. Seems to me that the Distance command should be more efficient With MMBasic PULSE / PULSIN I think you will need to toggle the I/O Pin direction. eg. (untested) [code] Get_distance: SetPin(15), DOUT pulse 15, .02 '// 20us pulse SetPin(15), DIN range = FIX(Pulsin(15,1)) '// Get Data / Conv to integer / (in us) 'do the math Pause 20 Return [/code] |
||||
Bill.b Senior Member Joined: 25/06/2011 Location: AustraliaPosts: 226 |
The distance command works OK with the SRF 0005 using one pin for tripper and echo. [code] do d = Distance(15) print d pause 1000 loop [/code] Now I have installed 4.5D I will try Goeytex's Code Edit: [code] do setpin(15), dout Pulse 15, .02 Setpin(15), Din d = Fix(PulsIn(15,1)) d = d/60 Print d pause 1000 loop [/code] this worked OK. I would say the Distance function would be similar in operation. I have not check the timing of either. Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
Print this page |