PWM output hi before any command sent??

Dear all,

I am currently testing the LabView for Arduino toolkit. I need to generate a 0-5V DC voltage out of a PWM channel to control the sensitivity of a photomultiplier. This control voltage will generate a high voltage of 0-1250V at the photomultiplier tube circuit. (I plan to use a 2-pole lowpass filter based on an LM358 OpAmp to smoothen the PWM signal)

I have so far just connected an LED (of course plus serial resistor) to the PWM output and can dim the LED with the PWM using a 0-255 control. So far so good.

However, when I connect the LED to the PWM output it is fully lit already when the Arduino (UNO) is conncted to the PC, even though the vi is not yet running, so the lopass would propbably already supply a full 5V to the photomultiplier at that stage. This is not good as a 5V output would switch the photomultipler to its full high voltage of 1250V instantly, whereas I would normally start much lower and increase hi voltage (= sensitivity) only as needed by the light levels.

As soon as I start the vi, the LED turns off and I can use the dial to adjust the brightness from zero to full, but the damage will be done to the photomultiplier already, because it receives a 5V control voltage from the Arduino even before the vi comes to play.

Why is the PMT output hi and not not zero before the vi starts??? What can I do to force a zero signal at the PWM output when the Arduino is connected to the PC but the vi to control the whole thing is not yet started?

Many thanks Holger

When the Arduino is reset the I/O pins default to INPUT. This looks like an open circuit to whatever is connected to that pin. A mild pull-down resistor should prevent the output from floating HIGH.

Which pin are you using for your PWM output?

Do you set pinMode()? It's not necessary when using analogWrite().

Do you use a digitalWrite() to set the pin to LOW in setup?

Perhaps there is a bug in your code but you'd have to post your code to get opinions on that.

The LabView interface uses its own sketch. That sketch is doing something to cause the pin to be high. So you need to go to those guys to figure out how to prevent the pin from defaulting output (and high).

How have you connected the LED?

As an aside, why go to the complication of building a 2-pole filter using an op amp and a pile of discrete components, when using a D to A chip would be much simpler?

Thanks for your help guys,

Well, I have posted the issue in the LabView for Arduino board but have not yet received a reply.

Why am I using discrete lo pass filters to smoothen the PWM into DC? Simply because I know how to do this :)

I have not connected a DAC chip to the Arduino - is there an example you could refer me to?

Cheers Holger

Connecting an SPI DAC chip to the Arduino is very simple, see attached schematic. You need 3 pins configured as digital outputs.

Ah - very easy indeed !

How would the sketch look like?

The only problem is then that I have uploaded the LabView toolkit for Arduino onto the UNO and presumbly I would need to add that code to the LabView sketch?


The code would be something like this:

const int dacCS = 2, dacSCK = 3, dacSDO = 4;  // define Arduino pin numbers connected to DAC

void setup()
  digitalWrite(dacCS, HIGH);
  pinMode(dacCS, OUTPUT);
  pinMode(dacSCK, OUTPUT);
  pinMode(dacSDO, OUTPUT);

void writeDacData(unsigned int data)
  // un-comment the following line if using MCP4911 (10-bit DAC)
  //data <<= 2;
  // un-comment the following line if using MCP4901 (8-bit DAC)
  //data <<= 4;
  byte msb = ((data >> 8) & B00001111) | B00110000;  // set unbuffered Vref, gain = 1, not shut down
  digitalWrite(dacCS, LOW);
  shiftOut(dacSDO, dacSCK, MSBFIRST, msb);
  shiftOut(dacSDO, dacSCK, MSBFIRST, (byte)data);
  digitalWrite(dacCS, HIGH);

OK - looks simple, many thanks again.


The LabView Toolkit should allow you to interface with SPI from your vi.

Thanks James, I have not yet submersed myself fully into the toolkit but will certainly do this.

For the time being I am just using a digital out pin and a logic level MOSFET to switch the generated DC voltage to prevent my photomultiplier to be forced to max. sensitivity on power-on.