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

PWM control on RB12 Relay board


  • Please log in to reply
4 replies to this topic

#1 mkelly

mkelly
  • Members
  • 11 posts

Posted 15 January 2013 - 11:57 AM

I currently have a PWM script to control AC Relays on FIO4 to FIO7 on this labjack U6. Which I will be disabling as only 4 channels can do PWM iirc


The current setup is 1Hz cycle time, using this code

// configure PWM timer:
//Set the timer/counter pin offset to 4, which will put the first timer/counter on FIO4.

AddRequest (ID,  LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 4, 0, 0)


// use system clock so works on U3 and UE9:
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc1MHZ_DIV, 0, 0)
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 15, 0, 0)

//Enable timers.
AddRequest(ID, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 4, 0, 0)

//Configure Timer0 as 16-bit PWM.  

AddRequest(ID, LJ_ioPUT_TIMER_MODE, 0, LJ_tmPWM16, 0, 0)
AddRequest(ID, LJ_ioPUT_TIMER_MODE, 1, LJ_tmPWM16, 0, 0)
AddRequest(ID, LJ_ioPUT_TIMER_MODE, 2, LJ_tmPWM16, 0, 0)
AddRequest(ID, LJ_ioPUT_TIMER_MODE, 3, LJ_tmPWM16, 0, 0)

//Set the PWM duty cycle.


AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 0, 65535 * ((PWMWidth1_1+100)/2)  / 100, 0, 0)
AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 1, 65535 * ((PWMWidth1_2+100)/2)  / 100, 0, 0)
AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 2, 65535 * ((PWMWidth1_3+100)/2)  / 100, 0, 0)
AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 3, 65535 * ((PWMWidth1_4+100)/2)  / 100, 0, 0)

//Execute the requests.
GoOne(ID)
ErrorHandler(ID)

Now I want to control a DC motor with a 12v relay. This means that I need to increase the frequency for that channel and add it to the PWM loop. It's the 7th relay on the RB12, which has a Dig Out # of 14

So here are my questions:

  • Can EIO channels do PWM or only FIO?
  • Can multiple channels have different frequencies on the same Labjack
  • Do the numbers on the RB12 increment after the default? IE: If the relay is on channel 14, so does that correspond to 14 when defining channels in coding.

Here's my thoughts on how I'd add in the code, define ID4 as the labjack the RB12 is hooked to. I'm disabling the FIO ports and only enabling the one EIO port (hopefully)

AddRequest (ID4, LJioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 14, 0, 0) // Offsets counter pin to start on channel 14


// use system clock so works on U3 and UE9:
AddRequest(ID4, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc1MHZ_DIV, 0, 0) // Enable frequency on channel 14
AddRequest(ID4, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 1, 0, 0) //Need to change these to the correct frequency

//Enable timers.
AddRequest(ID4, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 1, 0, 0) // Enable the single channel for control

//Configure Timer0 as 16-bit PWM.  

AddRequest(ID, LJ_ioPUT_TIMER_MODE, 0, LJ_tmPWM16, 0, 0) // Enable channel 14 for single 


//Set the PWM duty cycle.


AddRequest(ID, LJ_ioPUT_TIMER_VALUE, 0, 65535 * ((PWMWidth4_1+100)/2)  / 100, 0, 0) // enable PWM duty for channel 14


//Execute the requests.
GoOne(ID)
ErrorHandler(ID)

Thanks for the help!


Edit: I tested out the above code and didn't see any response out of EIO14.

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 15 January 2013 - 01:58 PM

Your first code block looks like it is doing PWM on FIO4-FIO7.


Can EIO channels do PWM or only FIO?

The valid range for TimerCounterPinOffset is 0-8, so the timers can start anywhere from FIO0 to EIO0. That means the highest channels the 4 timers can appear on are EIO0-EIO3.

http://labjack.com/s...users-guide/2.9

In your new code, you can't use a pin offset of 14. I am surprised you did not get an error.


Can multiple channels have different frequencies on the same Labjack

All PWM16 channels will have the same frequency, as there is only one clock source:

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

One trick you can do, though, is use PWM8 which will have a frequency 256 times PWM16 which you can see by comparing the formulas for frequency for each mode.


It's the 7th relay on the RB12, which has a Dig Out # of 14
Do the numbers on the RB12 increment after the default? IE: If the relay is on channel 14, so does that correspond to 14 when defining channels in coding.

The 7th relay position is associated with EIO6, which should be the label you see on the RB12. EIO6 would be channel #14:

http://labjack.com/s...users-guide/2.8

... but you can't use EIO6.

#3 mkelly

mkelly
  • Members
  • 11 posts

Posted 15 January 2013 - 02:00 PM

Your first code block looks like it is doing PWM on FIO4-FIO7.

The valid range for TimerCounterPinOffset is 0-8, so the timers can start anywhere from FIO0 to EIO0. That means the highest channels the 4 timers can appear on are EIO0-EIO3.

http://labjack.com/s...users-guide/2.9

In your new code, you can't use a pin offset of 14. I am surprised you did not get an error.

Is EIO0 the first channel on the RB12 or the last channel on the FIO?

Moral of the story is or is it not possible?

#4 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 15 January 2013 - 02:28 PM

FIO0-FIO3 appear on the U6 screw-terminals. FIO0-FIO7 appear on the DB37 connector. EIO0-EIO7 & CIO0-CIO3 appear on the DB15 connector. The RB12 connects to the DB15, so the 12 positions on the RB12 are associated with EIO0-EIO7 and CIO0 -CIO3, and should be labeled as such on the RB12 PCB. EIO0-EIO7 are channel numbers 8-15 and CIO0-CIO3 are channel numbers 16-19. Not sure what you are asking about as far as is it possible? It is possible to put the 4 timers on EIO0-EIO3. It is possible to have 3 PWM16 timers at 1Hz and then 1 PWM8 timer at 256Hz.

#5 mkelly

mkelly
  • Members
  • 11 posts

Posted 15 January 2013 - 03:54 PM

Not sure what you are asking about as far as is it possible? It is possible to put the 4 timers on EIO0-EIO3.

This is what I was asking


. I removed any of the FIO port references and set the offset to 8 so it starts on EIO0 then connected the DC motor to that relay instead of EIO6 and it worked!

Now just gotta find a good frequency to control at. 1 divisor the setup below works reasonably well, just a little pulsing.


edit: 60Hz seems to be a pretty good sweat spot. 180Hz was louder without any better performance.
// configure PWM timer:

AddRequest (ID3, LJ_ioPUT_CONFIG, LJ_chTIMER_COUNTER_PIN_OFFSET, 8, 0, 0) // Set offset to 8. Starts on EIO0

// use system clock so works on U3 and UE9:
AddRequest(ID3, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_BASE, LJ_tc1MHZ_DIV, 0, 0)
AddRequest(ID3, LJ_ioPUT_CONFIG, LJ_chTIMER_CLOCK_DIVISOR, 15, 0, 0)

//Enable timers.
AddRequest(ID3, LJ_ioPUT_CONFIG, LJ_chNUMBER_TIMERS_ENABLED, 1, 0, 0)

//Configure Timer0 as 16-bit PWM.  

AddRequest(ID3, LJ_ioPUT_TIMER_MODE, 0, LJ_tmPWM16, 0, 0)

//Set the PWM duty cycle.

AddRequest(ID3, LJ_ioPUT_TIMER_VALUE, 0, 65535 * ((PWMWidth4_1+100)/2)  / 100, 0, 0)

//Execute the requests.
GoOne(ID3)
ErrorHandler(ID3)



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users