communicating (data) between two boards

I am trying to implement PID speed-control of a mains-voltage motor. For now I have restricted the power to 70VDC via a transformer and rectifier.

The interface between Arduino and power is via transistors, 2N2222 at the low-voltage end, and Mosfets at the high-voltage end.

I have available an Uno board and an iDuino board and have tried each of them to generate suitable PWM output. They are both good.

For feedback I have a fixed slotted-opto 'looking through' holes in a disc on the motor shaft. This seems to me to give two options for the control board:
a/ read the holes with an Interrupt, and do something with it;
b/ read the frequency directly using pulseIn() and do something with it.

With the first method I have been charging a small capacitor then analogRead() the volts across it. Which takes time.
PulseIn() also takes time.

Either method limits the rate at which I can update my control so ....

I wondered if I could use one board for the PID / PWM Output and a second board to read/convert the feedback at its own leisurely pace, passing the result along 'a bit of wire' but without requiring the PID-board to do a (slow) analogRead().

Since the two boards will be side-by-side in the same enclosure, will I have to use serial/USB methods to communicate?

Regards,
Geoff

For feedback I have a fixed slotted-opto 'looking through' holes in a disc on the motor shaft.

place a LED behind it and a light sensor before and you can use digitalRead() iso analogRead().

Using interrupts is the way to go, search for rotary encoder on the forum ...

Thanks Rob, but I don't understand how digitalRead() works: ....Reference/DigitalRead offers no real ideas what to do with it, apart from reading the state of buttons.

Perhaps I should explain more of what I have been doing.

The required speed is got by analogRead() at the wiper of a potentiometer. Since this takes some time, I'm only doing it occasionally.

Each interrupt causes a small charge to be sent to a capacitor where they build-up a voltage, which is steadily leaked-away by a high-value resistor. As the motor is loaded-and-slows, the interrupt-sent charging will be slower than the rate of discharge, so the capacitor's voltage will go down.

This voltage, read via analogRead() every time around loop(), is an analog of motor-speed and is compared with the required-speed value.

Part of my problem seems to me to be that analogRead() happens at a fixed point in loop() but I cannot control when, relative to the interrupt-caused fresh charges - maybe this sketch will help.

Geoff

analogue_reading_errors.jpg

Blooming typical, isn't it! Drew that diagram and from it realised a possible cure for my problem - I've simply moved the analogRead(actual speed) into the Interrupt routine, so it reads the capacitor's voltage immediately after putting in another charge. The read is now at a known point relative to the charge/discharge cycle and the PID is behaving very much better.

Geoff

Telling your problem out loud is a well known way to tell your own brain what is happening :slight_smile:

Good it has been solved ( almost? ).

Thanks for that. However, it doesn't solve the more general question - how to communicate data from one Arduino to another?

Geoff

However, it doesn't solve the more general question - how to communicate data from one Arduino to another?

There are many ways to do that. Serial, I2C, etc. The amount of data to be transferred, and the speed that the transfer needs to be accomplished at matters.

Thanks, Paul, I think ....

Unfortunately that went right over my head - I'm still struggling to come to terms with grid-current in a triode-valve. I really am working hard at it but I'm getting too much homework (does the whingeing Pom, Limey bit.)

Seriously, I will try to study all the terms you just used, just give me a little time.

But now I've got my lathe under Arduino speed-control, I shall spend some time on my steam-engine. I only left off machining it to 'improve' the lathe several-weeks ago!

Geoff
P.S. We really were 'doing' triode valves when I was at school - the transistor wasn't invented until I was about 13-years old.

Unfortunately that went right over my head

Sorry about that.

I'm still struggling to come to terms with grid-current in a triode-valve.

I guess turn-about is fair play.

The easiest way is to connect two digital pins on one board to two digital pins on the other board. Use NewSoftSerial on each board to talk to the other board, just like Serial.

"turnabout is fair play" No, No, No, I didn't mean it like that - I thought we on here are All old-codgers :slight_smile:

I do like your suggestion of two-pins and serial-type transfer. I'll give it a try.

But not tonight, it's already past one A.M. time for a nightcap and hope to meet the Sandman.

G'night,

Geoff