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 : Trimming micromite clocks
Page 1 of 2 | |||||
Author | Message | ||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
On Micromites that run on an internal oscillator you need to use OPTION CLOCKTRIM to get the timing anywhere right for precision timing work. For normal programming, the defaout setting is more than accurate enough. Setting the TRIM value requires either running an oscillator and measuring the frequency (if you happen to have a frequency meter handy) or watching the time drift over a few hours. Introducing MM-TimeLord MMTimeLord loads a small program onto your micromite to send a short string to the PC every 10 (or whatever you set) seconds. The PC program times the incoming data to give a reasonably accurate indication of the micromites timekeeping ability. You can try different values for CLOCKTRIM and reload the program and try again. You can also set the interval for the timing data (default 10 seconds). This lets you run the system for long times and putting the micromite into a range of temperatures to see the changes. Set the com port, baud rate, CLOCKTRIM value and timing interval Click "Prog" to load the program onto the micromite - any existing program will be deleted. Start and Stop do what you would expect. If you change either CLOCKTRIM or Interval, you need to reload the program. If you try to run it on a micromite-plus which has a crystal, there will be an error when setting the CLOCKTRIM but it runs anyway. Each line of the printout is Computer time, last interval, average since start. 2016-01-26_045005_MMTimeLord.zip Earlier PC's did not have the high precision timer so this program will not function. I am not sure when it was introduced but I don't think anyone will run into the problem. Running high precision timers on a multitasking PC is a bit of a joke but I have been getting good results. I hope to have a Linux version running sometime soon. Jim VK7JH MMedit MMBasic Help |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1328 |
Jim - just gave this a go on the old XP system and got the data below connected to Mik's SMD Backpack running V5.1. It was connected via USB and the FTDI chip on the backpack. If you look down the data to time 20:47:30 you can see a bad result (big Interval/Average difference compared to most of the others). That came from me adjusting the size of the XP window as it was running. There are a few directly below it too that are anomolous which were caused by me leaving the cursor on the box edge - it went back to normal differences after I moved the cursor. Looks like you can't play with your PC when you're collecting your data. I looked at my differences too compared to your results and it's obvious mine has a poor precision. I wonder if that's because of my old slow XP system, or something else? Greg |
||||
Bizzie Senior Member Joined: 06/07/2014 Location: AustraliaPosts: 185 |
Jim, Not having any success with TimeLord. I can program the MM (same board as I used to update MMbasic). I can use TT to run your program in the MM and see the output BUT Clicking Start in TimeLord just locks the program (not output at all, Win10, TT stoped). TimeLord sees the comm port. Any ideas? Rob White |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
@Greg, I was expecting to see some jitter but not as bad as yours. TimeLord sets an interrupt to trigger just before the data is due to arrive. Windows puts its interrupts into a que and gets around to them when it gets time. In your case it's taking over one second to check the serial port. For best results, no playing games or surfing the net while doing the test. After the strange results (slow) we were getting with FTDI, I would be interested to see a comparison with a different chip and your PC. @Bizie, When you say no output, do you get the "time check started, Connected to Master..." lines? Jim VK7JH MMedit MMBasic Help |
||||
mindrobots Newbie Joined: 21/05/2014 Location: United StatesPosts: 32 |
Jim, Nice program! From my results, it looks like I need to set my trim value to -3.5 OPTION CLOCKTRIM -3 Connected to Master at 115200 16:57:20, Interval, Average 16:57:30, 9.998523, 9.998523 16:57:40, 9.998565, 9.998544 16:57:50, 9.998666, 9.998585 16:58:00, 9.998566, 9.998580 16:58:10, 9.998335, 9.998531 16:58:20, 9.998434, 9.998515 16:58:30, 9.998645, 9.998533 16:58:40, 9.998632, 9.998546 16:58:50, 9.998559, 9.998547 16:59:00, 9.998607, 9.998553 16:59:10, 9.998544, 9.998552 16:59:20, 9.998559, 9.998553 16:59:30, 9.998689, 9.998563 Time check stopped. > OPTION CLOCKTRIM -4 Connected to Master at 115200 16:59:58, Interval, Average 17:00:08, 10.003399, 10.003399 17:00:18, 10.003278, 10.003339 17:00:28, 10.003169, 10.003282 17:00:38, 10.003185, 10.003258 17:00:48, 10.003157, 10.003238 17:00:58, 10.003263, 10.003242 17:01:08, 10.003090, 10.003220 17:01:18, 10.003308, 10.003231 17:01:28, 10.003204, 10.003228 17:01:38, 10.003128, 10.003218 17:01:48, 10.003066, 10.003204 17:01:58, 10.003131, 10.003198 17:02:08, 10.003168, 10.003196 17:02:18, 10.003295, 10.003203 17:02:28, 10.003189, 10.003202 Time check stopped. With trim at zero, this MuP running 5.1 was getting a steady 9.985 Running on Win10. I was resizing windows, maybe going to a browser but nothing significant other than running your program. I'll try it again tomorrow on the same board with a -3 and -4 and see how stable it is. Well done! |
||||
Bizzie Senior Member Joined: 06/07/2014 Location: AustraliaPosts: 185 |
Jim, I get nothing! If I start TimeLord and click [program], then [start] this is all I get :- This is after at least a minutes wait. Rob Rob White |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
I can't understand why it's not working Rob. Try this update which has a couple of debugging steps in it. It will let me know how far we are getting. 2016-01-26_225811_MMTimeLord.zip Also, what chipset does your USB-TTL converter use? Jim VK7JH MMedit MMBasic Help |
||||
Bizzie Senior Member Joined: 06/07/2014 Location: AustraliaPosts: 185 |
Jim, Do not get much further :- Sorry image is poor, can not copy text as locked! I need to find a better way than Alt Print screen and paint. Not sure why the program did not show program - perhaps here's my problem! I have seen the tilder character and the message when ever I start TT with the MM already powered, I have always ignored this! I am using the freetronics usb-serial adapter chip is ATmega16u2 MCU see link. Rob White |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
I don't have one of your adapters so not able to test but we are making progress. Another version for you to try. 2016-01-27_010132_MMTimeLord.zip You can highlight the text in the output window and use ctrl-C to copy it. That makes it easier to read. Jim VK7JH MMedit MMBasic Help |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1328 |
OK, sure looks like FTDI (or their clones??) are a problem. Just repeated it on Mik's MUP with network disconnected (so no external interrupts?) and with MUP's on-board FTDI and got this below. Note the jump to 10 secs and bad results when I fiddled with window size again. It also takes a long time to come back to 'normal' - I wasn't fiddling after the first two 10 sec bad results. Then tried a standalone FTDI converter on a DIP 170 and got this. Pretty much the same crappy results - it 'looks' better because I didn't fiddle with the window size. Then tried a PROLIFIC converter (in a DKU-5 moulded cable - but the device manager does say it's Prolific), and got this. One hell of a lot better! I had another window size 'fidddle' at 55:46 and 56:35 to see if that still affected it - and it does. I could repeat this on a Win7/64 system if you think it might shed any more light. Greg |
||||
Bizzie Senior Member Joined: 06/07/2014 Location: AustraliaPosts: 185 |
Jim, That last version worked fine looks like my clock is close a value of -2 will correct it nicely. I have not seen the variations talked about by others. Will now try again to update an MM. Thanks Rob Rob White |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
@Greg, Any time you move or alter the program window, it will be too busy to check it's timer. If you slowly move the window around, the timer will never trigger, no matter what the PC is. There is nothing I can do about it (except learn how to do multithreaded applications). Playing with other windows should not have much effect. Different drivers for the various chipsets do seem to have different delays. I expect that FTDI are spending too much time checking for fakes! @Rob, Glad to see it working at last. A CLOCKTRIM of -2 tells me you are in a warmer climate than me. '-2' is also easily close enough for the pic32prog flashing program to work reliably but it could be a compatibility problem with the chipset. Jim VK7JH MMedit MMBasic Help |
||||
Bizzie Senior Member Joined: 06/07/2014 Location: AustraliaPosts: 185 |
Jim, Further to my earlier post. It is interesting your observations re temperature and clock speed as today is close to 10 degrees cooler than when I was testing yesterday! Thanks for your help. Rob White |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
When we first had CLOCKTRIM added to MMBasic, I did a few tests. I have made a couple of changes to MMTimeLord. There was a bug if you tried to use an update interval other than 10 seconds. I have added a percent error column to show that the default is still pretty good. Time check started.
Don't move or resize the window while timing! Connected to Micromite at 38400 > RUN 15:33:17, Interval, Error, Average 15:33:27, 9.961318, -0.387%, 9.961318 15:33:37, 9.961322, -0.387%, 9.961320 15:33:47, 9.961193, -0.388%, 9.961278 15:33:57, 9.961716, -0.383%, 9.961387 15:34:07, 9.961298, -0.387%, 9.961370 15:34:17, 9.961341, -0.387%, 9.961365 15:34:27, 9.961575, -0.384%, 9.961395 15:34:37, 9.961323, -0.387%, 9.961386 15:34:46, 9.960933, -0.391%, 9.961335 2016-01-27_045406_MMTimeLord.zip Jim VK7JH MMedit MMBasic Help |
||||
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2290 |
would it be practical to create a Cfunction that measures the length (in time) of characters sent to the console? if i am not mistaken, at 9600 baud, 8 data bits, no parity, character 0 will consist of a single negative-going pulse that is 9/9600 = 937.5uS long. if a Cfunction could route the console RxD line to a pin capable to timing the pulse, this could be used for calibration. even if rerouting were not possible, a simple wire between console RxD and another pin would suffice. to improve results, a string of character 0's could be sent and the measured pulse lengths averaged. it would be necessary to measure each individual character and average, rather than measuring a whole string in one go, as there is no guarantee that a UART may not introduce delays between characters. cheers, rob :-) |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1328 |
It's very practical as it is Rob. With a zero clocktrim (CT) my old system gives a difference of -0.014% and with CT at -3 gives 0.003%. It's stable to the 3rd dec.pl. difference for most 10sec. intervals (maybe Jim should make that 4 dec.pl.) but occasionally gives a kick, presumably due to something happening on the laptop. Certainly if you fiddle with the mouse or keyboard it changes. The runs below were all done at my 'best' setting (CT=-3) using the Prolific converter and no fiddling with mouse or keyboard. The first one had the browser open and network connected, for the second one I closed the browser and for the third I also disconnected the network; nothing else was running for all of them. They're pretty small data sets but it looks like the browser creates the occasional kick. I checked the task manager to see if anything obvious was happening with that 'noise' period but nothing was obvious. In any case, even with the occasional 'noise' kick it's obvious which is the best CT setting. Greg |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
I tried to come up with a system that worked on any 'mite without having to worry about any external circuit that might be in place. And I don't do Cfunctions (yet). When I did the temperature runs, I used a maximite to measure the frequency being generated by the micromite. That worked well but needed extra wiring. We are still only using an oscillator of unknown precision (in the PC) for our reference, so I am happy with the result. I need to compare a few different PC's to see what variation I get but don't want to get too hung up on the results. I could have printed out the timing in nanoseconds... Jim VK7JH MMedit MMBasic Help |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1328 |
Jim, Would you post how you calculate your 'error' please. Greg |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5907 |
percent = ((LapTime - interval)/interval) * 100.0
where LapTime = the measured time interval = the expected time Sorry about the slow reply. Yesterday morning the big fella in the sky tried to flash all my micromites at once. Lightning was almost a direct hit. Count so far is 2 routers including the one with my VOIP phone. 2 switches 4 raspberry pi's 2 laptops (My main PC and the one that holds the backups) assorted power supplies unknown number of 'mites 2 amateur radios - not cheap ones. 1 electric fence unit. I hate typing on this little laptop so it might be a while before there are any updates to my software. At least the hard disk was OK so the programs are safe. Jim VK7JH MMedit MMBasic Help |
||||
OA47 Guru Joined: 11/04/2012 Location: AustraliaPosts: 903 |
Jim, Sorry to hear about your losses. It happened to me a couple of years ago. Hope you can recover everything soon. (Your not near the fires as well are you) All the best GM |
||||
Page 1 of 2 |
Print this page |