I am a first time Arduino user and was tasked with this project at work.
The project is a safety inhibitor, which via a RS232 connection, stops a motor running if their is no communication between the motor and the computer running a control software.
I was given some bare PCB boards and the Arduino code that someone else wrote.
After building the boards and testing, the project is not working, so was hoping I could share the code here and if anyone could see anything obviously wrong with it?
Hardware wise, I am am using and Arduino Nano R3 for programming, and once the sketch complies and uploads successfully, I am transplanting the ATMEGA328P IC onto the PCB.
Thanks for the suggestion, but after I tried to compile that I got the following error message
In file included from C:\Users\dperry1\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.7\cores\arduino/Arduino.h:30:0,
from C:\Users\dperry1\AppData\Local\arduino\sketches\3749747396D0EAC91409A2C29A73C858\sketch\sketch_apr15a.ino.cpp:1:
C:\Users\dperry1\AppData\Local\Temp\.arduinoIDE-unsaved2026315-8732-1bltmnm.o2kk\sketch_apr15a\sketch_apr15a.ino:60:6: error: expected unqualified-id before string constant
void ISR(TIMER1_OVF_vect) // interrupt service routine
^
exit status 1
Compilation error: expected unqualified-id before string constant
You have a computer which controls a motor. You want to detect the failure case where there is no communication between the computer and the motor. You are assembling a system to detect this failure case. Is that right ?
I'd say that the best strategy is that the computer itself determines is there is a correct communication between it and the motor. It should then give some sort of regular "the connection to the motor is alive" message to a watchdog system. If that message is missing for a certain period of time, then the watchdog raises an alarm. Is this what you are doing, that is building such a "watchdog" ?
Maybe show a block diagram of the components of your system and how these are intercommunicating.
It would be better to rewrite it all from scratch - with a clear understanding of how the issue detection works (which you need to clarify).
A cleaner design is to remove the ISR entirely and reduce the system to a single periodic time check using millis(). The Arduino then maintains one piece of state: the timestamp of the last valid received command. This turns the problem into a simple asynchronous state machine driven by serial input plus time comparison.
I'm a bit tied to the existing system as it's for very old hardware, so just wanted to ask...is there a way to copy the working code from a known working ATMEGA328p ?
Sounds like what you're saying is along the way, source code revision control has been lost, and you're not sure what's really in there; the code you've presented is either:
a best guess at what might be in there
the most recent file you've located, which might or might not be anywhere near what's really in there
Is that the case?
If either is the case, you're back to defining what the real requirements are, from the system you have working in front of you.
I have just transplanted the known working 328p IC into a new PCB and it doesn't work, whereas transplanting one of the 328p's that I programmed into the known working PCB works...so therefore despite the seemingly wonky code, it's a hardware issue.
please explain, with some detail, just how you are testing the program! Are you actually monitoring the motor communications and interrupting it? I do not see the program giving any indication that it is running.
The whole project seems bogus. The RS-232 line is used by some other computer to talk to a motor controller, then this project also tries to SEND on the same RS-232 line a code to stop the motor. There can only be one sender on an RS-232 line.