FIRST Robotics Competition Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with PWM input

Solved!
Go to solution

Hi everyone, I have problems with the PWM ports using them as inputs.

What I am trying to do is send a signal 0 to 5v to the RoboRio, but I am using a PWM to generate it, the problem is that if I use an Analog Input instead, it does not work, as it detects the crests and troughs of it (0 OR 5), so I was trying to use the PWM port, as it actually has a Get Value vi (0-255), but even with that I am not able to get the value, it just shows "128" whenever I try it, I have applied different voltages to it (PWM and analog) and it keeps showing 128, could someone help me?

0 Kudos
Message 1 of 8
(4,156 Views)

If you're using one of the PWM ports, that's likely the issue here.  Taking a look at the roboRIO User Manual: http://www.ni.com/pdf/manuals/374474a.pdf page 13 has the pinout for those ports.  They're listed as Output only.  

 

I haven't tried to use the PWM Get value.  Though, I suspect that's limited to the MXP ports.  Those DIO ports are listed as Input/Output.

0 Kudos
Message 2 of 8
(4,101 Views)

PWM Get value just does a read back on the output ports (lets you "read" what value the output is currently set to).

 

You could write a "pulse in" vi using a Digital Input and a timer (fairly simple, I could give you an example if you would like).

 

Alternatively, what data are you trying to transfer? What is it coming from?

If it's from an Arduino or Raspberry Pi or other device that supports communications protocols like RS232 or I2C or SPI, or even serial via USB, you could transfer the data digitally.

(there are some examples of doing this with an Arduino here: https://github.com/mshafer1/frc-labview-workshops/tree/master/files/2018 but keep in mind that they are not fully documented, and had been meant to be viewed along with the webinar that was not recorded that year).

0 Kudos
Message 3 of 8
(4,083 Views)

Just read it, thank you

0 Kudos
Message 4 of 8
(4,035 Views)

Yes mjshafer93 I would like an example if you could help me with that, I am using an arduino to send the PWM signal, but I would like to see the pulseIn example too or any help you could give me

0 Kudos
Message 5 of 8
(4,031 Views)

> Just read it, thank you

 

...read.. the signal?

 

> I  would like an example if you could help me with that, I am using an arduino to send the PWM signal, but I would like to see the pulseIn example too or any help you could give me.

 

I'll try to post an example tonight/here in a little bit (I can work on this while at work, but don't have a machine setup here), I'm going to send you a PM with my email and phone number so you can ping me directly when you're working through this.

0 Kudos
Message 6 of 8
(4,020 Views)

I'm attaching a VI as an example of what you might need if you have to use the PWM/pulse width signal.

 

I you put this vi in Periodic Tasks, give it the DigitalInputDevRef for the input (DI) channel, wrap it in a tight loop (use a wait(ms) set to 1), and store the output ("Last pulse width (s)") in a variable, you can compare the value between .001 and .002 for a relative value. (This is assuming using the servo library to write the values, if using a true PWM, see https://www.arduino.cc/en/tutorial/PWM for relation of frequency vs pulse widths).

 

(untested!! - but I am confident it should work, but you should test it before using it).

pulseIn.png

 

 

Alternatively, if you just need to read a pulse at will, you could do something more like this:

linearPulseIn.png

where you block the rest of the execution waiting for the next stage in the pulse (not recommended, if a wire comes loose, you still want your drive to work!)

0 Kudos
Message 7 of 8
(4,007 Views)
Solution
Accepted by Teravolts

ks to everybody, at the end I was able to communicate using the I2C Serial protocol

0 Kudos
Message 8 of 8
(3,958 Views)