NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Sequencer project (help needed with timing)
April 21, 2012 by jfreethy |
Hello all, I wanted to get my feet wet after completing the Nerd kit projects and well here I am. I found that micro controllers could be very useful in my other hobbies. One of those hobbies being pyrotechnics, which I have been, involved with for about 12 years the last 5 being a licensed professional. But enough about me and on the project. The idea was to make a sequencer! Basically the user would input a standard delay in either minutes, second, milliseconds, or a combination of all three. Once the time for the delay was entered, the system would wait for an input signal (a stepped down voltage from the firing system). Once the voltage was received the “sequence” would begin to fire an output voltage (which would switch a mosfet) across my outputs at the desired delay. My out puts are leds currently. Here is the problem when I input minutes and seconds it will only display a value so high before it switched to a negative value and counted backwards. Those values being 32 for seconds and 3 for minutes, so I thought that it was an absolute value problem hence the abs in the code. Which none the less did not help. I think that the problem is that all my counting values are in milliseconds and that I am exceeding the total number of bites. Which I believe would result in me having to use some sort of timer in my code in place of just counting milliseconds. But I thought that I would ask here first being new The code is basic and rough but it’s my first code I did ;
|
---|---|
April 21, 2012 by sask55 |
Hi jfreethy Since none of the other member have posted a reply to your questions I thought I wouold make a few comments about your code. Keep in mind that a int16_t variable is 16 bit integer number. That means there are 16 bits of memory available to hold its value. One of the bits is used to indicate the values sign positive or negative, leaving 15 bits to store your values. 2 ^15 is 32768. The range of values that can be held in a int_16 is therefor -32767 to 32767. You could use uint16_t variables which would double the size of the possible value to 65536. Even that number would be a time of just over one minute in terms of milliseconds. Since each second has 1000 milliseconds and each minute has 60 seconds. Therefore to hold a time value expressed in milliseconds for time greater then about 65 seconds you will have to initiate the variable as int32_t or unit32_t A few more ideas. code lines 50 ,51,52 These variables are not used outside the main and could be moved down inside the main loop. code lines 53,54,55 This function is never called as you have written the code. You could just remove these code lines code lines 58,59,60,61 I don’t understand what your intent for these variables are, I do not see how they are used for anything in your code. code line 62 Variable to small to hold values. code lines 82,94,106,117 It is not clear what the intent of this code is. It does not change the values of the pull up resistors registers on port B. There is no need to change the state of the pull up resistors. This code could be removed. code lines 84,96,108, There is no need for the Absolute values here code line Since there are 60000 milliseconds in each minute this line should be a3=a3+60000. That is if you are intending to increment the time value by one minute changes with this button. You could consider holding your values for second and minutes as integer units and converting them to milliseconds to be added together in line 125. a2 would be a value held in seconds not milliseconds a3 would be a value held in minutes not milliseconds line 125 would be delay = a1 + (a2 * 1000) + (a3 * 60000); That change would eliminate the need for two of your variables delay_min and delay_sec. you would only require one large (32 bit) variable code lines 134,135,136,137,138, 139 you could consider to a single lcd_write_string(PSTR() line formatted to show your delay timing selections selection. I am not certain how clear or helpful any of this is. Many other memberson this form are much better at wtiting code then I am perhaps someone else will also post . Darryl |
April 21, 2012 by jfreethy |
Thank you for the comments sask55 I will review the changes that you suggested. Ans make some changes. |
April 21, 2012 by jfreethy |
After making some of your changes noted above i was able to extend the range of time out further for my needs. Thank you so very much! I knew that if i asked someone would be able to help me. On ward and upward to the next steps. j |
April 21, 2012 by sask55 |
That's great! Happy to be of some help. I think you will find this a very frendly, interesting and useful forum. |
Please log in to post a reply.
Did you know that signed numbers need to be sign-extended when chaging variable sizes? Learn more...
|