LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

LIFA - Read PWM Output

I'm using LIFA in a plugin architecture and would like to know if there is a way to interrogate the board to return the PWM value of a line. I'd usually just store the value in a table, but since my modules don't "know" each other, they have to be able to interrogate the board for the information separately.

My problem:

I was polling the board's outputs regularly with Digital Read Pins.vi and I thought that I would get random readings from the ones that were set to PWM (sometimes TRUE, sometimes FALSE), but instead, it changed the PWM setting to normal IO setting, and it reverted the line to a value of 1. Note that this was with Digital Write Pins.vi which would necesarily change it.

For example, let's say I configured line 10 for PWM and it was set at 191 (~75% duty cycle). After reading the output state, it got set as a solid 1, no PWM... My pump was always running at full speed. Each time I sent the command to set it to 192, 193, etc, it did so until the other program polled the value to display the current state.

I'll make a look-up table to skip the outputs that are configured for PWM and this will solve my problem for now, but my plugins will have to be linked somehow to access the same list, which means they won't be decoupled completely.

Would it be possible to read the current PWM value of a line in a future version of LIFA?

It would make it easier if the Pin Mode typedef also contained a third option: "PWM Output"...

GCentral ChampionCLA
0 Kudos
Message 1 of 3
(4,409 Views)

normandinf,

I'm not sure I completly follow what you are trying to do. 

If you enable PWM on a pin (set the pin as digital output) and write a PWM value of 191 to that pin you will get a PWM output with ~75% duty cycle on that pin.  If you then try to read from that same pin you will have to set the pin as an digital input using the set pin mode vi before you can read from it.  This will stop the PWM and you will read whatever is tied to that pin externally.  There is currently no way to read the PWM value that you set a pin to.  It would be easy to store this values on the Arduino or in LabVIEW and just look it up, but there is no way to read the value that you wrote directly.

That being said the value that you wrote is stored in a register on the Atmel so it does exits somewhere, it is just not made easily accessable to the programmer through the Arduino libraries and therefore not included in LIFA.  Some times microcontroller registerse will be write only.  I'm not sure if the Atmel timer registers are read / write. 

I think storing this values either in LV or on the Arduino with a customer command in LV would work best.

Let us know if you have any follow up questions.

-Sam K

LIFA Developer

Message 2 of 3
(3,110 Views)

I'd like to poke at the value directly from the Arduino, so if it was stored on-board and accessible with a LIFA command, it would definitely help me.

GCentral ChampionCLA
0 Kudos
Message 3 of 3
(3,110 Views)