I'm in the learning stages of programming and would like your opinion on my proposed method of doing some fast data logging for just about half a second.
I have a plasma cutter for cutting steel. To turn on the plasma arc, the machine receives a start signal, then goes through a process to establish the main arc. I want to do fast sampling of the arc voltage from when the start signal is received to when the main arc is established.
During this arc establishment process the voltage can go as high as 230 volts. So to interface one of the Arduinos analogue inputs I was thinking of using an isolated power supply for the Arduino and using a common ground with the plasma cutter arc voltage. Put simpler the ground of the Arduino supply will be connected with the ground of the plasma cutter arc volts. Then a voltage divider network will give 5 volts to an analogue input pin when the plasma arc voltage is at its max of 230. I'll also add some protection with a 5.3v zener and a small fast blow fuse.
Having read about the source resistance needing to be a max of 10Kohms, I might also use an op-amp buffer circuit to take the 0-5v signal from the voltage divider and give a very low impedance source voltage to the analogue read pin.
As for the sketch, my idea is to change the analogue resolution to 8 bits (accurate enough for my needs) so it can be stored as one byte, and store each sample in an array. I will be using the 2K of SRAM, not the EEPROM (too slow). Once the array is full the sketch would upload the numerical values to the PC. That's it.
If the Arduino fills the array too quickly (i.e. before the main plasma arc is established) I could simply put a delay between samples to lengthen the time between sampling and thereby extent the total period that samples are taken.
The timing is not so critical. I mainly just need to see what the voltage is doing from when the start signal is given to when the main arc is established.
Does the above sound a reasonable way of doing this. Just want to get some feedback before I go wasting time learning how to write a sketch that is doomed to fail for some reason.
I had a glance through some of the Instructables pages and I think its a bit too heavy going for me at present. I'll be happy for now if I can just grab my 1000+ voltage samples in about the 1/2 sec period.
1000 samples will use a lot of your RAM (assuming you are using a Uno).
If you save the value from the ADC into a byte you will automatically lose the top two bits - perhaps no need to change the resolution of the ADC. Just make sure your max voltage is divided so it is below 1.25v
Unchanged, the ADC will read 1.25v as 255 which gives you the full 8-bit resolution assuming the Aref is 5v.
I couldn't see the forest for the trees. I was so focussed on the Arduino power supply and the arc voltage having a common ground that I never thought about possible differences in voltage between the arc voltage ground and the PC.
Guess now a question I have is can I "hot connect" the USB cable from the Arduino to the PC. If that is possible my sketch would have to pause the code after the array is full, then I'd disconnect the arc voltage signal, connect the USB cable, and press a button which tells the Arduino to upload the array values to the PC.
yes a lot of the ram will be used. My teaching book has a little sketch that can measure how much ram you have available. I think you add the code into the main sketch. My storage array will have to be a bit smaller than the reported free ram (beginner talking here remember so if I'm talking out of my arse please feel free to tell me XD). I've read that the Arduino compiler has no means of checking if an array I create is using more ram than what is available so I have to be careful in that area.
Interesting workaround on the ADC but when operating with 10 bit resolution, won't the Arduino still record two bytes of data even if the value is below 255. I'd have thought the upper byte would simply be all zeros.
The ADC will return an integer (two bytes) but you only need to save the low byte in your array.
Start your project with a small array and get it working. Then you can enlarge the array in later versions until it gets too big and stops working. Then go back to the previous version!
Normally you can't "hot connect" the USB cable because that causes the Arduino to reset and lose its data. There are techniques to prevent the Arduino resetting and Google will remember them better than I can.
@Grumpy_Mike's suggestion saves plugging and un-plugging (and forgetting to unplug).
I'm starting to wonder if I should change my tactics and go for something like a voltage controlled oscillator for the HV side and a frequency to voltage converter on the Arduino side, and isolate the two with an opto isolator.
Don't know what I was worrying about. After lots of Googling it seems many are having plenty luck using a capacitor from RESET to GROUND. Needs to be a big enough cap to keep the voltage on the RESET pin propped up while the auto-reset line is trying to pull it low.
My board also has the RESET-EN pair of pads with the skinny link between. Cutting that link severs the auto-reset path. It would be much better if that had been made as a replaceable link on the board.
Having found all that info, I've dug out an external power supply for my Arduino Uno clone (Freetronics Eleven R3) and tried plugging and unplugging the usb cable to the PC, and it is NOT causing any resets.
The usb connection is good because I can upload sketches to the board.