![]() |
counting digital input
How do I count digital input ticks?
Im trying to get our autonomous mode to work before our regional this Thursday. Im using the banner optical switches to count ticks on my wheel that I painted on with reflective paint. We have tank style right and left side steering. I estimate I want to move 43 ticks forwared and turn say right with 4 ticks on one side and 1 tick on the other. I then want to move both sides forward 3 ticks. I figure from read chief delphi I can do this using 3 "states" Forward_long, turn and forward_short. However I dont know much C just enough to cut and paste or substitute. 1, How do I make a counter that keeps track of the number of ticks the digital input gets. 2. Where do I put the code for the timer? Where do I put the code for the states? thanks in advance! |
Re: counting digital input
Either use polling, meaning you check for a change in state of the digital input every loop, or use interrupts. As you don't have much time, I would recommend the polling, as it can be done easily with no bugs.
For the polling you would have something like this: Code:
// This is the output that anyone can read. Rename it to something better and more descriptive--EDIT-- If you want it to only catch one type of state change (IE low to high), then have it check if it has reached the state you want it to before it increments. |
Re: counting digital input
Thanks Texan
And which file.c do I put this code in?? And how could I do say a case for autonomous_1 where I go left and autonomous_2 where I go right useing the digital input. And once again which file.c do I put it in? |
Re: counting digital input
All Autonomous Code goes in user_routines_fast.c
|
Re: counting digital input
Thanks CrashZero!!!
So my last question is how to I put a switch on my digital inputs so that I have one that turns left and one that turns right etc. I imagine it is some sort of If statement but I dont know how to put all the brackets, parenthesis etc If digitalinput15=0 then autonomous_1 else digital input16=0 then autonomous_2 else end something like this? and do i put the counter in each automous module? each of my autonomous modes has three states, forwardstate turnstate and forwardshortstate. How do I group these together with regards to brackets, parenthesis into autonomous_1 and autonomous_2? thanks again!!! |
Re: counting digital input
Quote:
Code:
if(dig_in_10 == 1)Quote:
|
Re: counting digital input
None of that is going to work if you're going at any resonable speed. It's going to miss ticks. Use interupts.
Here's some of my code: Code:
//Variables |
Re: counting digital input
Quote:
But, I agree with you. Use interrupts if you can. |
Re: counting digital input
Quote:
Code:
void Int_1_Handler() |
Re: counting digital input
Sorry, I just copied and pasted. I don't think I even use it.
|
| All times are GMT -5. The time now is 17:06. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi