[SOLVED]Changing values in for/next loop or delay values

I have two switches that can be activated in any order. If switch 1 is activated
I start timer1 and check switch 2. if it is activated I stop the timer ,set an interrupt
on switch 2 and start a counter(b5) counting from 0 to 3 seconds.
When switch 2 is activated the interrupt service routine resets counter b5 to 0 and
increments a counter by 1 and keeps counting as long as switch 2 is reactivated
within 3 seconds. If switch 2 is activated first everything works the same by exchanging
switch1 and switch2 in the explanation.

I can’t seem to get either of the Arduino schemes to work - seems it is not possible
to modify the for/next loop in the first or the delay value in the second. Anyone know
of a way to do this?
Thanks, Al Hooper.

(Picaxe Basic code)
set interrupts

for b5 = 0 to 30
pause 100
next b5

;ISR
among other things sets b5 to 0 and increments a counter by 1 each time
switch 2 is activated.

(Arduino code on a Pro-Mini)

attachInterrupt(0,eastern,RISING); attachInterrupt(0,eastern,RISING);
for(kount = 0;kount < 30000;kount++); delay (dltime);
//ISR //ISR
void eastern() void eastern()
{ {
kount = 0; dltime = 30000;
count ++; count ++;
} }

Al, your explanation of what you want is very unclear and the code you posted is garbled and make no sense at all.

Start over. Explain what the purpose of your circuit is and describe the operation step by step as if you were talking to an intelligent but non-technical friend. Do not mention interrupts in your explanation, they are not relevant to the explanation (and won't be needed in the code either, I am pretty sure).

Read the forum rules before you re-post, so you know how to use code tags.

Hi,
Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

What is the application that needs the timer manipulation?

Tom... :slight_smile:

Seems to me like a state diagram and table would be the easiest way to explain this one.

What I want to know is - can I reset ‘kount’ to zero while the for/next loop is running using the ISR
“eastern”.

attachInterrupt(0,eastern,RISING);
.
.
 for(kount = 0;kount < 30000;kount++);
.
.
void eastern()
 {
kount = 0;
count ++;
}

What I am doing is detecting a train with one switch - measuring how much time elapses until the train encounters the second switch. The elapsed time will give me the speed. I then use the second switch activations to increment a counter by using the ISR, this gives me the number of axles. If the second switch is not activated before six seconds elapses, the count is stopped and the results are displayed. Here is the unit in action.

Thanks
Al

I doubt it.

The compiler will probably optimise that for-loop away completely. It will take zero time to run. So the ISR won't be able to influence it.

This works by using ISR western to reset variable “i” on each interrupt(until 6 seconds expire with no interrupts.). I have to figure out how to enable/disable interrupts as they now kill my timing calculations. I have never written in C -(NS)- even now - just converting a Picaxe Basic program.to run on a Pro Mini.

I invite you guys to visit the Picxe Forum at: http://www.picaxeforum.co.uk/forum.php
Al
PS SEI/CLI fixed that - everything AOK thanks to Nick Gammon.

attachInterrupt(1,western,RISING);
   interrupts();

  i=0;
while(i < 100){
 delay(50);
 i ++;

}void western()
{
 count ++;
i = 0;

}

What nonsense. I was a regular contributer to the Picaxe forum for a couple of years and can assure everyone that the excellent people there would have been as bemused by your befuddled ramblings as we are.

Paul:

Sorry I offended your sensibilities.Have you helped others as you did me or are
you on here just to troll. Did your propensity to troll and/or your attitude get you
kicked off the Picaxe Forum?
Regards
Al

Sorry I offended your sensibilities

Sorry if reaction to your totally incoherent ramblings causes offense. But we do get pissed off here by people who can't be arsed to read the forum rules. How to use this forum
You must have missed the bit about posting ALL your code. Those fragments are insufficient to detect where you have made the error. Are the variables volatile? If not you can't use them inside and outside of an ISR.

I have never written in C

Then give some respect to people who have and tell you things like:-

The compiler will probably optimise that for-loop away completely.

The C language is compiled not interpreted and optimization can produce unexpected results for a beginner.