Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

Sample code for PWM?


  • Please log in to reply
7 replies to this topic

#1 forrest_higgs

forrest_higgs
  • Members
  • 5 posts

Posted 28 September 2014 - 07:01 PM

I need to drive a power transistor to control a process heater.  Has anybody got sample code in VB.NET or similar that lets you do PWM control?

 

Thanks!

 

Forrest



#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 29 September 2014 - 08:06 AM

Which device are you using?  What frequency do you want to use?



#3 forrest_higgs

forrest_higgs
  • Members
  • 5 posts

Posted 29 September 2014 - 08:16 AM

I'm using a U3-HW.  The frequency is negotiable.  I set up a nested timer in VB.NET to emulate a PWM signal, but the practical frequency I got with that was in the hundreds of cycles/sec.  I need at least low thousands.  



#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 29 September 2014 - 08:26 AM

PWM16 is for 732 Hz or lower, so you want to use PWM8:

 

http://labjack.com/s...s-guide/2.9.1.2

 

In your configuration set TimerClockBase and TimerClockDivisor to get the desired frequency:

 

PWM8_Frequency = (TimerClockBase/TimerClockDivisor)/256

 

Then in your main code whenever you want to set the duty cycle you pass a TimerValue of 0-65535 that specifies what portion of each cycle is spent low out of 65536.

 

Start with the LJUDDotNet example U3_TimerCounter for the traditional add/go/get method of writing those things, or see U3_EFunctions to use eTCConfig & eTCValues for the config and updates.

 

Also, before you attempt it in VB.NET, I suggest you first play with it using the test panel in LJControlPanel.



#5 forrest_higgs

forrest_higgs
  • Members
  • 5 posts

Posted 29 September 2014 - 08:32 AM

Thanks, I'll try that just now.



#6 forrest_higgs

forrest_higgs
  • Members
  • 5 posts

Posted 01 October 2014 - 10:29 AM

Got it running on the control panel and in VB.NET.  So far, no problems.  Wish people who wrote example code weren't so interested in impressing people with how sophisticated they are in the language, though.  That's something I see with practically every piece of example code that I have to deal with.  Makes life difficult if you're a beginner.  :-p



#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 01 October 2014 - 11:44 AM

We actually make a purposeful effort to keep our examples as simple as possible.  We are not trying to teach people the language, but just show the interface between the language and the LabJack.  It is in our best interest to do that, so we are just supporting our interface and not supporting the programming language in general.  For the most basic examples, you might look at the VC6_LJUD archive.  These are usually plain old C with no GUI.



#8 forrest_higgs

forrest_higgs
  • Members
  • 5 posts

Posted 01 October 2014 - 12:08 PM

I'm not real fond of console apps.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users