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 : DM timing microsecond?
Author | Message | ||||
robarino Newbie Joined: 15/03/2012 Location: SwedenPosts: 24 |
I was wondering if any of you had used the auidio pulse as a counter. I am using the duinomite mega and I need to count with an accuracy of 10 microseconds. I can send a sound out at a frequency of 100 kHz from the audio jack. The question is how do I count the number of cycles in MMBASIC? Thanks! Rob |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
Hi Rob, I answered this in your email so this is more for someone else in the forum who might have the same question. It assumes that the sound output is connected to pin 13: SOUND 100000, 3600000 ' 100KHz for a long time (1 hour)
SETPIN 13,5 ' set pin 13 as a counting input ... PRINT PIN(13) ' get the count ... PRINT PIN(13) ' count should have incremented etc. Geoff Geoff Graham - http://geoffg.net |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6098 |
I did this for an ultrasonic range detector. 58 uS delay equals 1 cm so a sound frequency of 17241 Hz was used. Every 100mS, the program sends a start pulse out pin 15 then waits for the return pulse. The sound output is connected to pin 11 which does the timing. settick 100, mainloop
waitloop: if cnt=0 then goto waitloop if cnt <650 then print cnt*10 cnt=0 goto waitloop end mainloop: cnt=0 sound 17241, 20000 setpin 15, 8 pin(15)=0 pulse 15, 0.02 pause 0.03 setpin 15, 6, begincount ireturn begincount: setpin 15, 7, endcount setpin 11, 5 ireturn endcount: cnt=pin(11) sound 17241, 0 setpin 15, 2 ireturn VK7JH MMedit MMBasic Help |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2914 |
Hi Rob, Using Geoff's example on the DuinoMite you will need to use Pins 5,6 or 7 as the count input as he has quote Maximite Pin No.s so where he quote pin 13 you need to replace it with one of the others as here SOUND 100000, 3600000 ' 100KHz for a long time (1 hour) SETPIN 5,5 ' set pin 13 as a counting input ... PRINT PIN(5) ' get the count ... PRINT PIN(5) ' count should have incremented You will also need to use line numbers, Hmm, On second thoughts, Maybe all of the above depends on which firmware you are using... If DM firmware (olimex) then what I said above is correct, if using Geoffs 12 pin MM firmware then what Geoff said is correct (I assume pins 10,11,12,13 are the count inputs on Geoff's DM version of MM 3.x).. Now, depending on exactly what you mean to do 10us is very fast... each basic instruction, I believe, takes 30uS to process so doing something with 10uS accuracy is going to difficult come impossible. Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
robarino Newbie Joined: 15/03/2012 Location: SwedenPosts: 24 |
WOW Thanks for all that! Geoff the initial code that you wrote was exactly what I was doing. Now I am sure that is right...I think my confusion is the pin setup on the duinomite mega rev c. I have plugged in the grounf from the headphone jack into the ground on my board. I then tried to plug in the signal to lots of different ports and get nothing. I am using this document and it says pin A4, A5 and D10 with corresponding pin names 13,11,9 So I write this connected to A4: [code] SOUND 100000, 3600000 ' 100KHz for a long time (1 hour) SETPIN 13,5 ' set pin 13 as a counting input ... PRINT PIN(13) ' get the count ... PRINT PIN(13) ' count should have incremented etc. [/code] @Tassyjim I don't need the timing for processes per se. I am measuring mechanical vibrations and I need a timer that could count by 10 microseconds. If I sample at 2 kHz I can live with a timer of 500 microseconds with +/- 9.99999 microsecond accuracy. To be honest I am shocked at how fast the sd card writes. It completely blows NETMF out of the water for sd write times and array filling. I have run this code numbered and I get 1's from every port. In addtion MMBASIC will only allow setpin 12,5 and setpin 13,5. Frankly it there is a little confusion on my part concerning the olimex hardware documentation...pins layout etc. In this respect I would like to contribute though by taking the Arduino examples and rewriting them in Basic for the beginners though. Those resources help a lot. DUINER.com |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Rob, There's a page and a half discussion on using the Maximite for exactly this in the March issue of "Silicon Chip" (pp 68 Circuit Notebook section). It involves a small amount of external circuitry but apparently gives a resolution of 5 microseconds. Greg |
||||
Print this page |