Spark Core vs. Photon Pin Difference

Hi,

Now that I finished my Control Box I wanted to test all parts and if they are working as intended. I have 2 SSRs, HLT and BOIL heat element, controlled by PIN A0 and A1 and on PIN A6/DAC and A7/WKP the 2 pumps.

The heat elements will be controlled via the software PWM but the pump speeds should be controlled via direct Voltage output form the Pins itself, 0 to 5V. (Measured max Voltage was 4.84V on these Pins)

On the Core all pins used on the BrewPi Spark are PWM capable, but on the Photon A0 and A1 are not PWM capable. That means I need to use A6/DAC and A7/WKP for the pumps. Testing the pump speed with the Tinker App shows that the A6/DAC has a range from 0 to 4095 (12-bit) and the A7/WKP a range from 0 to 255 (8-Bit)

How you plan to handle the different ranges of that pin to control the pump speed? I guess the firmware will handle that transparently?
Are you planing to use different Pins in the future to be able to support PWM on all connectors?

Thank you,
Thomas

From memory @Elco said he will probably have an external module for controlling pumps rather than using the PWM onboard the photon/spark

Why would you have an external module? What is the benefit?

My control box has a power supply for 17V that can handle both pumps. The power needs 2 wires, plus and minus. I added a 3 pin connector where 2 pins are for power and 1 pin for PWM. I run a normal 3 wire from the control box to the pumps. Simple I thought.

BTW. Just tested the A6/DAC pin and it does not do PWM as expected. So controlling 2 pumps with BrewPi and Photon directly via pins is not possible. That is a bummer. My enclosure plan and assembling went down the drain. Not a good feeling.

We’re doing software PWM for heating elements, because we can then do other smart things like:

  • making sure that no 2 elements are on at the same time
  • driving PWM over OneWire
  • This is slow PWM with frequency 1/4 Hz (4 second period), which is not suitable for driving pumps.

What you are asking for is hardware PWM from the Photon’s peripheral modules. We did not code it like that, because the outputs were meant for controlling AC devices, which cannot be controlled by fast PWM.

As a hobbyist, with the need to just control one DC pump with PWM, I would have used the DAC pin. But this will require the user to wire up a transistor board. For a user friendly way to support controlling pumps and fans, I would make this transistor board a bit bigger and add:

  • A small microcontroller that communicates with the Spark
  • and creates the PWM signals
  • And Reads the pump/fan speeds if supported (for example for PC fans)
  • Has transistors on board to switch the higher voltages and currents

Hmm. My original idea was to use the PIN directly to drive the speed because the PWM output depending on the value with analogWrite changes between 0 and 3.3V. In general would that work or does it not work if done that way?

But here is the funny part that confuses me: I have the BrewPi Spark v2 with a Photon. The A7/WKP changes the voltage based on the analogWrite (0 to 255) from 0 to 3.3V directly measured on the Photon PINs. If I measure on the green connectors I get 0 to 4.84V if 12V is connected (or 4.55V connected via USB). On the A7/DAC port on the other hand changes the voltage based on analogWrite (0 to 4095) from 0 to 3.23V at the Photon PINs. Measured at the green connector I get a total different picture. If the value is above ~1515 I get 4.55V, and if the value is below ~1515 I get 0V.

Why is that? Is that connector differently connected to the PIN in comparison to A7 with the fourth connector?

There is a digital level shifter IC between the Photon and the green outputs.
This is because the photon runs on 3.3V and SSRs are happier with 5V.

So you cannot use the analog output of the pin through the green connectors. You’d have to connect it to the photon directly to bypass the level shifter.

Which makes sense and would be not a problem. The pump wants to 0 to 5V to control the speed, so to increase the voltage from max 3.3V to 5V is very welcome here. The pure output voltage of the Photon of 3.3V would not be enough to get the pump to full speed anyway.

I get what you are saying but that is not what I was referring to. I like to understand why there is a different behaviour on the A6/DAC pin in comparison to the A7/WKP pin. Both are connected to the level shifter but the output behaviour is different.

I made some more measurement on the level shifter. The pin 3A (9) is connected to the DAC pin of the Photon. The input voltage changes based on the value set via analogWrite correctly. The pin 3Y (8) seems to have a threshold when you are over it provides the full power of 4.54V (USB powered), below that value is is 0V. Whereas the pin 4A (12) receives also variable voltage based on analogWrite values. But this time the 4Y (11) output pin changes the voltage based on the input voltage.

Reading the spec for the IC, I have not seen anything that states that pins on the IC are treated differently. Could it be the IC is faulty or the the A6/DAC output is different to the A7/WKP and therefore the level shifter reacts differently?

Just try to understand how the things are working.

I am guessing, because I do not use this functionality myself:

The photon has a true DAC, the pin outputs an analog voltage. See 3.35:

With Arduino, they call it AnalogWrite, but it reality it is PWM (so fast alternating digital). The Photon has true analog output, which obviously won’t work well with a digital level shifter.
This will match your observations: the level shifter just toggles when its analog input reaches the threshold.

Makes sense. Thank you for the help and information.

Now I need to find a way to control the speed of my pump via software in a different way. Looking into using directly pin A4 or A5, as you said, with an additional level shifter from SparkFun so that I get 0V to 5V.

Any idea where I can steal the 5V from?

Fingers crossed that this will work and the pumps change their speed from off to full speed.

My plan was to use a small microcontroller (small AVR or even ATTINY) to generate the PWM signal locally and have it talk to the main controller over RS485.

However, RS485 is not part of the current firmware yet. There is a chip on the board for it, because I thought it would make sense for actuators and sensors that cannot be connected via OneWire.

If you want to help out in getting that going, perhaps prototyping with an Arduino or second Photon, I’d be happy to supply parts.

An alternative could be this:
https://www.maximintegrated.com/en/app-notes/index.mvp/id/4627
The circuit can be simplified because of high input impedance of the pump (mega-ohms).

But I would feel more for a smart expansion board with its own micro that can drive multiple pumps or fans.

You can get 5V from the RJ12 pins.

Nice idea.

Found this on ebay: http://www.ebay.co.uk/itm/x1-x5-DigiSpark-KickStarter-ATTINY85-micro-USB-Development-Board-Arduino-TESTED-/262221494251?var=&hash=item3d0d9e77eb:m:muX6o596XwilXll2IXX2fgQ
Can be used for the development/test setup?

Would put a RJ12 female connector in front to get the RS-485 and the 5V + GND from the BrewPi and connect 2 pumps (or fans) to it. From the specification I have 2 PWM I/O on this board that provide 0 to 5V which would be enough to drive the speed of the pump. There are 4 more I/O that provides digital output or ADC.

Do you have docs that would guide me how to use the RS-485 with the BrewPi/Photon?
How would you address this MicroController board, unique ID received from a discovery scan? Have not read anything about a unique id yet. If you have several controllers you would need to have a way to address them, I guess.

Another thing I discovered. I’m not an electric engineer or electrician so I learn on the fly at the moment.

I have 17v power supply for both pumps in my control box, and a separate 12v for then BrewPi. The pumps + and - are coming from the 17v power supply. The PWM or HIGH signal comes from the BrewPi.

With his scenario the pumps are not moving at all. Removing the PWM cable makes no difference.

Then unconnected one pump to the 12v power supply, same as BrewPi. This time if the PWM was 0 or LOW the pump was off. Setting a PWM signal between 0 and 255 made the pump work with different speeds. Setting it to HIGH and the pump was working full speed.

It looks like the PWM signal voltage must have the same ground as the + and -. The design of the microcontroller board must take that into consideration. Means the PWM signal powermust also use a level shifter that uses part of the 17v to generate the 0 to 5v PWM signal.

Can a level shifter with different power and ground do that? What can be used to do that?

When you connect 2 boards with different power supplies, you always need to connect the two grounds, so the boards have the same reference voltage.

It is recommended to feed your PWM signal into an RC low pass filter to convert it to analog DC

Can I just put a cable between the 2 power supply - ports and that’s it? Does not cause problems?
Just a dummy question because this is new land to me.

Yes, GND to GND (minus to minus). Voltage is always relative to a reference. If you don’t connect these references, the control signal will float.

Test it yesterday and worked absolutely fine with the only PWM pin.
But I have to admit the difference in pump speed is not that much, it might be because the PWM signal is not as you said a correct analog signal.

I received all the parts for the RS-485 test setup and will try to put something together and make a small application to see if it works.

What pins on the BrewPi are you using for the RS-485? Reading through the internet tells me there shoul dbe 2 pins you are using to talk with the transceiver.

There is a MAX3082 RS485 tranceiver on the board, connected to:
RX (3), TX (4) and TX_EN (D6).

Maxing TX_EN high goes to send mode, low goes to receive mode.
From there, you can just use Serial1. Serial is mapped to USB communication Serial1 is for the rx/tx pins.

The outer pins of the RJ12 connectors are the RS-485 A and B outputs.