jorgeal 0 Posted July 7, 2008 Report Share Posted July 7, 2008 Hello, I´m a newie. I started with the proyects posted in section for beginners and I have the following problem: I tested the proyect "binary progression" and all works ok in simulation, but when I wired in a proyect board, the delays programmed run faster than should be. I measured about 200ms with my oscilloscope and the programed value was 500ms , its a big difference. Later I changed delay_ms(500) for delay_s(2). In this case it works ok, ie programmed values are very similar to measured ones. Is there a range values that could be used inside delays functions like delay_ms ?? any help? thanks Jorge Quote Link to post Share on other sites
Reynard 0 Posted July 7, 2008 Report Share Posted July 7, 2008 delay_ms only takes an unsigned char value therefore should be in the range 1 - 255. Page 69 of manual. To get 500ms call the delay_ms(250) twice. Cheers Reynard Quote Link to post Share on other sites
jorgeal 0 Posted July 7, 2008 Author Report Share Posted July 7, 2008 Thanks Reynard, I suspected it!. So there are in the Forum at least 3 or 4 wrong examples using delay_ms(500). The corious thing is that they work fine with the simulation software without any warning or error message. bye. Jorge Quote Link to post Share on other sites
Pavel 0 Posted July 8, 2008 Report Share Posted July 8, 2008 ... So there are in the Forum at least 3 or 4 wrong examples using delay_ms(500).The corious thing is that they work fine with the simulation software without any warning or error message... You'll get a warning if you use -W2 compiler command line option (all warnings). And for simulator there is nothing to report because by the time code gets executed under sim it already uses a converted value. Regards, Pavel Quote Link to post Share on other sites
Reynard 0 Posted July 8, 2008 Report Share Posted July 8, 2008 Hi Jorge, As Pavel says, if you turn on 'All Warnings' you would have gotten a warning informing of loss of data. You can use the command line setting or in the IDE use 'Settings -> Options...' then click All Warnings. The compiler demoted your value of 500 by truncating to the last 8 bits leaving you with 0xF4 or 244ms as you got. All Warnings is good for beginners as it can pick out simple unintended errors of loss of data etc. It is also useful for experienced programmers to run their code through the All Warnings occasionally. We all have senior moments. Cheers Reynard Quote Link to post Share on other sites
jorgeal 0 Posted July 8, 2008 Author Report Share Posted July 8, 2008 good, I did it and now I can see the warning. Thanks for your time. Quote Link to post Share on other sites
russ_hensel 0 Posted July 12, 2008 Report Share Posted July 12, 2008 Most ( all? ) times you use a variable that is too small for a value the value will "roll over" 255 + 1 = 0, etc. You can use a bigger variable type, but if the function does not honor it you will still not get what you want. Sticking to unsigned char gives the fastest code, but the most limited. good, I did it and now I can see the warning. Thanks for your time. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.