I have an Arduino Nano installed on a board that is supposed to generate pulses and pulse trains to an AND gate.
I am powering the board (and the Arduino) using a 15V power supply stepped down to 8V with a mini DC-DC step down buck converter.
The problem is the board generates the required pulses for a short time, then it stops. I have to either press the reset button or unplug/plug the power in order to get it working again.
Hello shamooooot
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс
First thing I see is you should never detach and attach interrupts in an interrupt function. They are already disabled and will be enabled when the function ends. Attach interrupts ONE time only in setup.
We can't help much if you are just copying code you found somewhere. You actually need to understand a bit about what you are coding.
What are you trying to accomplish?
@shamooooot You’re doing well so far, and this isn’t a response to anything you’ve said, but it’s easy to get defensive and shut down.
You’ll find the whole team here are extremely well qualified to solve your problem, but some of them may seem to be like the kids at school that gave you a hard time.
Yes, sometimes we’ll pull your pants down, or give you sh|ts, but if you work calmly through the conversation you and us will. one out enter off.
None of us know everything, sometimes there’ll be some stupid answers or unnecessary questions, but with a bit of patience - it WILL work !
So I am trying to make the Arduino generate a single pulse or pulse trains through pin 9.
I also have two switches: one for stopping the Arduino of generating signals (inhibit),
the other switch is for changing from single pulse (square wave) to pulse train.
I was testing and I found out the reset happens when I switch these switches, and it is pretty random. I even sometime lose the software on the Arduino and had to re program it.
Are the switches momentary switches? Or toggle switches?
I think the interrupt attaching and detaching and debouncing are interacting unexpectedly. Why do you need the interrupts?
You can inhibit the pin9/OC1A/OCR1A PWM by clearing this COM1A1 bit. Are you using pin10/OC1B/OCR1B for anything? Otherwise this COM1B1 looks like a mistake:
If you want to do this with timer registers, there's a cool trick for doing one-shot pulses with a timer by setting OCRnx above TOP: AVR Timer-based One Shot Explained | josh.com -- you might be able to do the pulses, inhibiting, and pulse trains all with OCR1A, ICR1, and TCNT1 manipulations.