Arduino : Run Function on Rising Clock Edge

Can you post your code and maybe a timing diagram for the problem? I notice you’re on a Due so I want to make sure you aren’t triggering on HIGH rather than RISING. Barring switch bounce it should really only trigger on the rising edge, so all this supporting circuitry for the 555 shouldn’t be needed.

In fact, technically none of the external circuitry is needed, though interrupts are crucial to learn, so good on you for doing it in a more interesting but convoluted way. Timers are microcontroller peripherals designed for exactly the purpose you mentioned: running code or commanding pins at ultra precise intervals.

Hi James
I think the problem is (apart from wiring errors) that if the arduino finishes while the 555 pulse is still HIGH then it provide a reset signal which “unlatches” the 74LS02 and because the "SET signal is high it immediately will SET and start the Arduino cycle again. Bu differentiating the rising edge of the 555 pulse and using this spike to latch the 74LS02 and then disappear the IC will not Set again until the next 555 rising edge occurs. I think this is a valid idea and fairly simple to implement.
Cheers Bob

1 Like

No Just the inputs. The outputs will take care of themselves.
Cheers Bob

Why the SR Latch

This has been my problem. Thanks Robert.

Why am I doing this

Hi @James. All of this is strictly for my own education. None of it is necessary. I could code up some C++ to do the same thing. This is not to say that I don’t have more to learn about software. I’m just enjoying hardware for a while and trying crazy over designed ideas seems to be the quickest way to learn :slight_smile: . Fail Faster Approach.

This however is very cool. Maybe once I’ve got a handle of the 555 timer I can decide to simplify everything and use this approach.

#include <DueTimer.h>

void setup() {
  Timer3.attachInterrupt(blink);
  Timer3.start(500000);
}
int LED = 10;
int state = LOW;

void blink() {
  state = !state;
  digitalWrite(LED, state);
}

void loop() {}

Wiring Errors

Oh boy lot’s to check there.
I think I’ll deconstruct it a bit and recheck the wiring to make sure everything better. Then I’ll clean up or make a new diagram.

I’m also working my way through Differentiator articles.

1 Like

Hi Pixmusix
As promised here is your marked up original circuit diagram.
Note the diodes. They are essential. The lack of them might have been the cause of the funny smells you mentioned. I would start with brand new (never used) ICs anyway. Those would have to be suspect.

Also a couple of 10kΩ pull downs and the grounding of all unused inputs.
The passive differentiator is between the diode junctions and the '02 gate input.
The 100kΩ resistor value is not particularly critical, anywhere between about 47kΩ and 100kΩ should be OK. This resistor doubles as the pull down for this input so it doesn’t float.
The cap might be marked 1nF, 102, .001µF or 1000pF. All the same value. Type could be MKT, 50V or 100V monolithic etc.

Carefully check your wiring and resistor values or you might need a steady supply of ICs.
Cheers Bob
EDIT…
Just spotted something. Try this first but you might need another pull down from the junction of the 2 diodes cathode (the pointy end with the cross) to ground. This to discharge the capacitor between pulses. The 2 diodes I have inserted will prevent discharge via the '08 outputs. anywhere between 10kΩ and 100kΩ should be OK.

1 Like

@Robert93820 thankyou for your timer preparing this.
I’ll give it a shot soon and I’m sure I’ll have many questions. :slight_smile:

Hi Pixmusix
I have to go to Brisbane urgently to-morrow and will be away all next week so might be a bit late answering any queries. Sorry 'bout that
Cheers Bob

1 Like

366305121_126434097162846_7705949531947420552_n

Hi Everyone.

I’m not sure I understand exactly how to bread board this part of the diagram @Robert93820 so kindly penned up for me.

What I tried :

  • I connected the outputs of my and gate via diodes to row 18 of my breadboard.
  • I used a 1 nano-ferret capictor to connect row 18 → 19.
  • I passed a the signal from row 19 → 20 with a simple cable.
  • I then passed row 20 → 21 with a 100k resistor.
  • I then passed row 21 to ground
  • I also passed row 21 back to row 20 with another diode to complete the loop.
  • Lastly I took a second signal from row 19 → the SET input of my SR Latch (row 22).

Using my multimeter row 18 is HIGH and row 19 is LOW. Something about my loop, or my capacitor, is preventing row 19 from going high (?).

Anything I didn’t understand about this diagram? What am I missing?

Hi Pixelmusix
Just now got home and confronted with this.
Firstly. The use of terms like “row 21, row 20” is Swahili unless one knows what these rows are connected to. Especially as the numbers don’t appear in your pix.

Next to the pic itself. This looks as if it should work BUT
What exactly are those diodes. Don’t look anything like 1N4148. More like the 1N400X series of power diodes. These would be useless in this application.
Exactly what is that capacitor. It looks suspiciously like a ceramic and if it is it would be lucky to be more than 100pF. Not 1nF (1000pF). By the way, the term is FARAD not FERRET, That is an animal.
Did you not read the whole of my last large post. I don’t see any sign of a resistor from the junction of the 2 diodes to ground. Without this the capacitor will only probably charge up for the first pulse then do nothing if it cannot discharge. That is what the extra resistor is for. This would be in your terms from row 18 to ground.

In a nutshell if you are going to go off with what you think are the correct parts and not use what is advised there is not much anyone can do for you. There are diodes and diodes, capacitors and capacitors, different types have different tasks and uses.

You also haven’t answered the questions I raised about the 82 and 22 ohm resistors in your earlier pics yet. I don’t think the 2 logic ICs will drive LEDs, The 555 might but not with 22Ω limiting resistors.

The capacitor would for a start. That is what capacitors generally do, remove any DC component.

I think I have worked out which rows are which. Row 18 should be pulsing high courtesy of the 555. If you have a continuous stream of pulses of 50% duty cycle a multimeter will read the average which will be half the peak value. This will change with different duty cycles.

IF YOU FIT THE COMPONENTS I NOMINATED you should have a narrow positive going pulse at row 19 corresponding to the rising edge of the pulse at row 18. This will be only a few µsec and will NOT be readable with a multimeter. You would need an oscilloscope which I doubt you have.
If as I suspect you have fitted components unsuitable for purpose you could have anything or nothing. If you don’t fit the extra resistor I spoke of you would probably only get the first pulse and then nothing until the capacitor was discharged.

During your research I suggest you look up how to get the best out of your multimeter. Namely what you can and just as important what you cannot expect to measure.
Cheers Bob

EDIT. Apologies. Ceramic capacitors would appear to go up to 8200pF or 8.2nF. I was not aware as I have only used them as RF bypass up to about 100pF. They may be OK for this application but I did the tests with monolithic cap.

Add on
Just had a closer look at your pic and compared with your “circuit diagram”.

You have the capacitor, 100k resistor and diode junction point (or row 19/20) connected to pin 1 of the "02 instead of pin 2 and pin 2 going off somewhere via a blue wire. I suspect you have the connections to pin 1 and 2 of the "02 (row 22, 23) reversed.

I would also strongly suggest you be very much more careful in the future as this sort of thing could be serious. Also very misleading and awkward if you can’t trust the constructor (you) to be accurate. This sort of thing renders any diagnostic effort meaningless. That IC could now well be suspect and I would suggest the bin.
Cheers Bob
PS. That yellow wire does not look right either. CHECK THE WHOLE THING

Hi
I have done a quick sketch of what you should have as a differentiator…

The diodes HAVE TO BE fast signal diodes. 1N4148 will do the job but 1N5819 might be better as they are fast schottky diodes and have a bit lower forward voltage drop. Both types are readily available.

I have done a couple of checks and the 10kΩ cap discharge resistor IS required, The reason is that the 2 diodes from the "08 prevent the cap from discharging via that path so discharge has to be via the 10kΩ resistor.

Wire as per this diagram and fix possible wiring errors as I spotted above and all should work.

Will do you a “proper” schematic as soon as I get a chance.
Cheers Bob

1 Like

Hi @Robert93820

Just wanted to jump on and write a quick reply to let you know I’ve read all your posts. :slight_smile:
I’m so very grateful for expertise and the time you’ve put in.

I’ve got a few projects this week, but I will try and find some time to go shopping and buy some of the parts you suggested. Once I’ve sourced the specific diodes and caps I’ll have a close read of some of your solutions and have another crack at it.

Do you mean dangerous to me or dangerous to my components? I guess I’m willing to make a few mistakes if it means I just have to replace a few components every so often. Is it possible to start a fire doing a small project like this?

Thanks again.

Hi
Dangerous to components. Could have a fire but I doubt it. The biggest danger is mental. You could go in circles for days and get nowhere all because of a problem you have built in. Not to mention the time wasted trying to help remotely. If you are not accurate with your build skills and describing problems accurately you really have very little chance of success. Far better to check and check again to be sure even before switch on.

Photos can be useful but unless the pic subject is really what you want to see can be of not much use. Like your method of quoting row numbers then providing a photo that does not show them. I just got a bit lucky and was able to identify 18, 19 etc by where the components were. That is when I picked up your connection mistakes.

It can be hard. For instance you still have not told me exactly what those diodes are, or verified the capacitor value, or even what the 82Ω and 22Ω resistors are. I have said before that sometimes getting accurate information is like pulling teeth. I generally don’t do it too long before I think about walking away. Lack of patience in old age probably. So lets try to get it right.
Cheers Bob

I’m sure as I improve I’ll learn how to give accurate useful information.
For example until reading your posts I didn’t even know diodes were different.
I just went into a jaycar and asked for a “diode” and they sold me a pack of 10.
Now that I know not all diodes work the same, and that the type of capacitor matters, I’ll dig through my receipts and figure out what model numbers I bought.

Or better yet, I’ll just go and buy the correct parts. :slight_smile:

As a fun aside, I originally read 1nf as INF as in short for infinity! :man_facepalming:
I have a long way to go :stuck_out_tongue:

I understand that working with novices can be very frustrating.
I do appreciate that you have been so patient and helpful.

Reading through what you wrote I think my next jobs are :

  • Figure out what I used
  • Source precise parts listed
  • List out the precise values of ALL my equipment
  • Redraw my best (and first) real circuit diagram

Hi

That explains a bit. Probably as I suspected, the 1N400X series of general power rectifiers, OK at 50 or 100Hz but more or less just a piece of wire at higher frequencies. You might only have a square wave at 100Hz but to reproduce a square wave with a fast rise and fall time the frequencies involved are very much higher than that. Too complex for here but Google “square wave” for more info.

In this instance case matters. It is 1nF (not 1nf), note lower case n and upper case F. F for Farad and n for nano. A bit of research required here, fractions like milli (m), micro (µ), nano (n) and pico (p). Then multipliers like kilo (k), mega (M), giga (G) and tera (T) are common. It is useful to get a bit familiar with these abbreviations.

Components are made of different materials and have different construction which dictate their use somewhat. Some capacitors (electrolytic) have too much inductance for RF use as do some resistors, particularly wire wound power types. Even carbon film and metal film are made in a spiral which can have appreciable inductance and not much use at higher frequencies. Very hard to get a truly non inductive resistor but they do exist.

So you see there really are horses for courses and that is the reason for some form of identification and data sheets. Ignore them at your peril as you are no doubt now becoming aware of.

I will draw you one in the next couple of days and you will see that the symbols actually mean something and far easier than boxes where you have to look up a data sheet anyway to find out what all the pins connect to inside.

Keep going. It takes some time so don’t lose patience as us old blokes sometimes do.
Cheers Bob

Hi Pixmusix
As promised here is a schematic of what you have done (or should have done) including the differentiator and pull down mods.

The differentiator components are C1, R4, D3 and R3 is the capacitor discharge resistor (required).

Note the pull down resistors R1, R2 (required). Also the grounding of all unused inputs (required).

Note the LED limiting resistors increased to 330Ω. This will result in 10mA which should be plenty.

C2 and C3 are power rail bypass caps which may not be required. If needed fit as close to IC pins as possible.

I see on your earlier Pic you have a LED fitted to the latch output probably for an indicator during testing. This has a 100Ω limiting resistor. I don’t think the 74LS02 will supply that sort of current (about 30mA) so if you really need an indication change this to 1kΩ. This will limit the LED current to about 3mA which should be OK but the LED might not be very bright. This should not matter as it should be only a temporary indicator.

I have not included the 555 part of the schematic, only shown the input from 555 pin 3 to this bit. Good exercise for you.
Cheers Bob

1 Like

Hi Bob.
Just checking in to say I haven’t forgotten about this project.
I’ve have a few more personal life challenges to take down and then I’ll dive head first into this with actual Cap values and such.
Thanks again for your assistance :slight_smile:

Hi @Robert93820.
Just wanted to come back here and let you know that I was successful in building what your beautiful schematic. I sat down with a friend of mine and we made a weekend project of it. It’s sent me down a real rabbit hole of discovery!

I have purchased The Art of Electronics and have been reading it on my weekends. If I had my time again, now having read up a little more, I would have started this dialogue with much more information. I’ve realized the importance of accurate values, model numbers, and diagrams that are drawn correctly.
Thanks for bearing with me while I honed these skills.

For the record, I did integrate my this little clock with my larger project. I’ve since decided to scale that down a little and the SR Latch is no longer required. I don’t regret learning to make one those.

I think the most useful this I learned from this thread was the importance of diodes when using one way capacitors.

I had heaps of fun trying to make my SRLatch Idea work.
I’m really grateful for all your efforts and education.
So much information here. Reading back on it I understand it a lot more now.
Thanks Bob.

Pix.

3 Likes

Hi Pixmusix
Good to see you had some success and a bit of fun along the way.

If you are keen, get the basics under your belt. Volts (V or E), Current (A or I) and resistance (R or Ω(ohms) for DC then the same for AC except add in Reactance (XC for capacitive reactance and XL for inductive reactance) similar to resistance in DC except for phase shifts. Also C (usual designation C) for capacitance measured in Farads or fractions of (µF, pF etc) and L for inductance measured in Henrys or fractions of (mH, µH etc). Don’t ask why this is “L”, I have no idea.

If you master or at least have some understanding of most of that the rest will get a whole lot easier down the track.

Cheers and good reading Bob

1 Like