I have a UNO generating 5 pulses repeated each second. The sequence in uSec is
3000 HIGH, 1000 LOW, 900 H 900 L, 300 H, 900 L, 300 H 900 L, 300 H 900 L
The attched sketc1 displays in SM all the HIGHs in sequence. Sketch2 chnages the order from X,Y to Y,X and when run displays all the LOWs sequentially. My many attempts which have been extensive, to combine these two sketches into one have failed. I want one sketch to display in SM the HIGHS and the LOWS in order. Extensive internet searches reveal no solution
Please show your sketch in the post between code tags. The </> button is for code tags.
It this your very first program ever ?
You could make it more readable. This is exactly the same as what you have:
// Example Code IntChange-09 Idee nouvelle
volatile int pwm_value = 0;
volatile int prev_time = 0;
int x = 0; char C = CHANGE;
char X = RISING; char Y = FALLING;
void setup()
{
Serial.begin(115200);
// when pin D2 goes high, call the GUP function
attachInterrupt(0, GUP, C);
}
void loop()
{
}
void GUP()
{
attachInterrupt(0, GND, Y);
prev_time = micros();
}
void GND()
{
attachInterrupt(0, GUP, X);
pwm_value = micros() - prev_time;
if (pwm_value > 200)
{
Serial.println(pwm_value);
}
x++;
if (x > 24)
{
while (1);
}
}
Can you explain what your project is. What is a SM ? Are there two sketches ?
It seems as if you want to invert a signal. You can do that with a logic gate or a transistor.
About your sketch: Use one interrupt and keep that active. Keep the interrupt routine as short and as fast as possible. Don't use a Serial function in the interrupt routine, and no while-loop. Read the level with digitalRead() in the interrupt function. Then gather two times with micros, but perhaps just one will work or perhaps more than two. If you really want to recognize the pulses at high speed, then I would add a ringbuffer.
I have a UNO(1) generating 5 pulses repeated each second. The sequence in uSec is
3000 HIGH, 1000 LOW, 900 H 900 L, 300 H, 900 L, 300 H 900 L, 300 H 900 L
A separate UNO(2) recives the pulse train on D2 Int0, its interrupt.
The attached sketch1 displays in Serial Monitor all the HIGHs in sequence. Sketch2 loaded on UNO(2) changes the order from X,Y to Y,X and when run displays all the LOWs sequentially. My many attempts which have been extensive, to combine these two sketches into one have failed. I really want one combined sketch to display in Serial Monitor the HIGHS and the LOWS in time order. Sketch2 is identical to Sketch1 except that X and Y are reversed.
I'm sorry you cannot understand my English too well.
Please post the program that is transmitting the pulses and the two different programs that are receiving the pulses.
And also post the program that represents your best attempt at merging the two receive programs together with a detailed description of what happens when you run the merged program.
17391939:
Thanks I will post the generator sketch tmro. It's 23.15hrs here time for sleep.
Interrupt generator Sketch 433TestGen-01.ino and combined Interrupt Sketch, which is rather messed up at the moment, is Sketch IntCombo-02.ino. Both are attached
Those codes are small enough that you can post them in-line. Please do so using code tags so they are nicely formatted as the code in Reply #1 is. That will make it easier on the folks you are asking for free help from. Why make them download your code?
If you want an interrupt to run different code on different occasions just put all the code in the ISR and select which piece is appropriate depending on the value of a variable. Something like
Attached slightly better version of the combined Sketches. This further attempt does show on Serial Monitor either HIGHs or LOWs when order of interrupts is change but not both during same run-time.
Rgds Michael
Hello Robin2 I will give that code idea a whirl. BTW I have read all the documentation on interrupts widely. My next challenge will be to user timers directly for more accuracy of needed, but I'm a long way off doing that yet.
Rgds
Michael
17391939:
Attached slightly better version of the combined Sketches.
Seriously??? Is there something about the previous requests that you didn't understand?
Koepel:
Please show your sketch in the post between code tags. The </> button is for code tags.
gfvalvo:
Those codes are small enough that you can post them in-line. Please do so using code tags so they are nicely formatted as the code in Reply #1 is. That will make it easier on the folks you are asking for free help from. Why make them download your code?