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

U3 and PWM


  • Please log in to reply
6 replies to this topic

#1 matt_kiz

matt_kiz
  • Members
  • 9 posts

Posted 26 October 2009 - 01:47 PM

I am trying to do motor control with a PWM signal, but I'm having trouble generating the signal. I am using DAQFactory Express with the following code: [codebox]using("device.labjack.") include("c:\program files\labjack\drivers\labjackud.h") try global ID = 2 global PWMWidth = 50 private talkback AddReuest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 6, 0, 0) //FIO6 AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 1, 0, 0) AddRequest(ID, LJ_ioPUT_COUNTER_ENABLE, 0, 0, 0, 0); // disable Counter0 and Counter1 AddRequest(ID, LJ_ioPUT_COUNTER_ENABLE, 1, 0, 0, 0); // for good measure //This should give me a PWM freq. of ~977 Hz AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc1MHZ_DIV, 0, 0) AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 4, 0, 0) AddRequest(ID, LJ_ioPUT_TIMER_MODE, 0, LJ_tmPWM8, 0, 0) talkback = GoOne(ID) ? "GoOne(ID) = " + talkback ErrorHandler() set_pwm() catch() endcatch[/codebox] I get no errors when I run this code, and GoOne(ID) returns 0. I then configure a Variable Value component on one of the GUI pages to set the global PWMWidth value, and issue a call to set_pwm(): [codebox]using("device.labjack.") include("c:\program files\labjack\drivers\labjackud.h") private talkback try AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 0, 65535 * PWMWidth / 100, 0, 0) talkback = GoOne(ID) ? "PWM = " + PWMWidth + "%" ? "GoOne(ID) = " + talkback catch() endcatch ErrorHandler()[/codebox] The global PWMWidth variable gets updated correctly and set_pwm() is called and executes correctly, but I don't seem to be getting any signal on FIO6. I assume I should see the PWM across FIO6 and Vs; is that right? I've tried putting a scope across those pins (as well as across FIO6 and GND), but I don't see anything except noise. I also tried to set up FIO7 as a timer to measure duty and hooked up FIO6, but no dice (FIO7 didn't change at all when I modified PWMWidth). Is there anything obvious that I'm doing wrong? the GoOne() calls return 0, so it looks like the U3 is accepting the commands. Thanks for any insight you are able to give. -Matt K.

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 26 October 2009 - 02:18 PM

Few things: 1) Use the test panel in LJControlPanel to try turning on the PWM output and viewing it on your scope. 2) Try the example TimerPWM.ctl mentioned in Section 10.5.1 of the DF-LJ App Guide. 3) Your pin offset command has a typo in the function name ("AddReuest"). Not sure why you don't get an error, but will ask AzeoTech to take a look.

#3 matt_kiz

matt_kiz
  • Members
  • 9 posts

Posted 26 October 2009 - 05:12 PM

Few things:

1) Use the test panel in LJControlPanel to try turning on the PWM output and viewing it on your scope.

2) Try the example TimerPWM.ctl mentioned in Section 10.5.1 of the DF-LJ App Guide.

3) Your pin offset command has a typo in the function name ("AddReuest"). Not sure why you don't get an error, but will ask AzeoTech to take a look.


I confirmed operation with the LJControlPanel, and then checked out the typo. That was indeed the problem. Thanks for the suggestions!

-Matt

#4 Susi

Susi
  • Members
  • 31 posts

Posted 24 July 2012 - 08:36 AM

Hello, I need to generate a PWM output to control a servo, but a need PWM freq. of ~50 Hz, and I need to be able to control the %. I have look every where but no luck, please can someoen help me, I'm ussing Matlab too. Thanks

#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 July 2012 - 09:05 AM

Start by reading about PWM16 in Section 2.9.1.1:

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

Then go into the test panel in LJControlPanel and try using it.

Then go to matlab and start with an example that uses a timer.

#6 Susi

Susi
  • Members
  • 31 posts

Posted 24 July 2012 - 03:07 PM

Start by reading about PWM16 in Section 2.9.1.1:

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

Then go into the test panel in LJControlPanel and try using it.

Then go to matlab and start with an example that uses a timer.


I try whit the Labjack panel but I couldn't program the signal, I new whit this. And I already read the section of the manual that talk about the PWM signal but I'm still having problems

how can I configure it the pwm signal with the Labjack panel??

#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 24 July 2012 - 03:49 PM

Have you gone through the quickstart on the U3 Support Homepage:

http://labjack.com/support/u3

In the 4th bullet you configure a timer, so that should give you a feel for that.


You need to look at Section 2.9.1.1 and determine the settings you want for TimerClockBase, TimerClockDivisor, and Timer Value. For 50 Hz, I suggest TimerClockBase = 48MHz /Div and TimerClockDivisor = 40, which will give you a frequency around 52 Hz.

Timer Value should be set as desired to get your duty cycle. Start with perhaps 62000.

You want "# of Timers Enabled" to be 1, and "Pin Offset" of 4. That will put your timer on FIO4.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users