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

timer setup using low level commands?


  • Please log in to reply
7 replies to this topic

#1 dougm

dougm
  • Members
  • 11 posts

Posted 05 January 2010 - 05:14 PM

I'm working on WinCE (still) so am having to use the low level commands to get things going, and I need to setup a PWM signal to drive a stepper driver. I Started with ConfigTimerClock (5.2.4) and believe I have it setup correctly: [codebox]sendBuff[1] = (byte)(0xF8); //Command byte sendBuff[2] = (byte)(0x02); // magic number sendBuff[3] = (byte)(0x0A); // another magic number sendBuff[6] = 0; //reserved sendBuff[7] = 0; //reserved // TimerClockConfig // Bit 7 configure the clock so 1 // bit 6-3 not used? so 0000 // bit 2-0 TimerClockBase (12Mhz/Divisor) so 101 // so 1000 0110 = 0x86 sendBuff[8] = (byte)(0x86); sendBuff[9] = (byte)(0x28); // Clock Divisor=d40, so 0x28[/codebox] I think the next step is to use a Feedback command to send a Timer#Config command (5.2.5.16) but I'm confused by the fact that it's got one byte (0) and two IOType numbers (page 106): Timer#Config, 4 command bytes: 0 IOType=43,45 1 TimerMode 2 Value LSB 3 Value MSB Can you explain to me (preferably with a short code sample) how I would form a packet to configure this command? Also, after I configure this, how do I actually turn on and turn off the PWM signal? Are there any steps I'm missing? Thank you, DougM

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 January 2010 - 06:24 PM

Before sending the ConfigTimerClock command, you should send a ConfigIO (Section 5.2.3 in the User's Guide) command first to enable Timer/Counter lines, then a ConfigTimerClock command to configure the clock and last the Feedback command to set the individual Timer settings.

In the ConfigIO command, in byte 6 set the writemask for FIOAnalog and TimerCounterConfig, in byte 8 set the Timer/Counter pin offset, enable Counter 0/1 and the number of Timers to be enabled, and in bytes 10 and 11 set the Timer/Counter lines to digital. For example to enable Timer 0 on FIO4 the command would look like this
sendBuff[1] = (uint8)(0xF8);  //Command byte
sendBuff[2] = (uint8)(0x03);  //Number of data words
sendBuff[3] = (uint8)(0x0B);  //Extended command number
 
sendBuff[6] = 5;  //Writemask : Setting writemask for timerCounterConfig (bit 0) and FIOAnalog (bit 2)
 
sendBuff[7] = 0;  //Reserved
sendBuff[8] = 65;  //TimerCounterConfig (binary00000001 + binary01000000) 
sendBuff[9] = 0;  //DAC1 enable : not messing with this
sendBuff[10] = 23; //FIOAnalog: setting FIO0-3 as analog, FIO4-7 as digital (binary00001111).  Really just need FIO4 to be digital.
sendBuff[11] = 0; //EIOAnalog : Not setting anything

As for the Feedback command, look at the IOTypes table in Section 5.2.5 of the User's Guide (page 100) to clarify what IOType is associated to what Timer. IOType 43 if Timer0Config and IOType 45 is Timer1Config. As for a Feedback command for configuring Timer 0 to say 16-bit PWM with a 25% duty cycle (value of 49,152), it would look something like this:
sendBuff[1] = 0xF8;  //command byte
sendBuff[2] = 3;  //number of data words (0.5 + 2 for Timer0Config + .5 for padding)
sendBuff[3] = 0;  //Extended command number  
sendBuff[6] = 0;  //echo

sendBuff[7] = 43;  // IOType = 43 (Timer0Config)
sendBuff[8] = 0;  //TimerMode = 0 (16-bit PWM output)
sendBuff[9] = 0;  //Value LSB
sendBuff[10] = 192;  //Value MSB

sendBuff[11] = 0;  //padding
See section 2.9 for Timer/Counter documentation. In particular in this section the TimerMode values are specified and each mode is documented (Value is explained).

As for turning off the PWM signal, disable the Timer line that the PWM is set to using ConfigIO.

#3 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 05 January 2010 - 06:30 PM

Also note that if using a TimerClockBase with a divisor, Counter 0 is disabled and cannot be used. Section 2.9 documents this.

#4 dougm

dougm
  • Members
  • 11 posts

Posted 07 January 2010 - 02:00 PM

Great thanks - that was exactly the information I needed to get going. Everything is working ok. DougM

#5 gnasen

gnasen
  • Members
  • 3 posts

Posted 25 October 2012 - 05:18 AM

I have the same Problem, I want to send a trigger Signal via LabJack and hit the limits with the USB connection (around 10ms it gets unaccurate). So I tried to setup a timer and tried the following:
#include "u3Base.hh"

u3Base u3b(1);

int main(void)
{
  u3b.getConnecID() 

  uint8 buffConfigIO[12];
  buffConfigIO[1] = (uint8)(0xF8);  //Command byte
  buffConfigIO[2] = (uint8)(0x03);  //Number of data words
  buffConfigIO[3] = (uint8)(0x0B);  //Extended command number
  buffConfigIO[6] = 5;			  //Writemask : Setting writemask for timerCounterConfig (bit 0) an$
  buffConfigIO[7] = 0;			  //Reserved
  buffConfigIO[8] = 65;			 //TimerCounterConfig (binary00000001 + binary01000000) Timer on F$
  buffConfigIO[9] = 0;			  //DAC1 enable : not messing with this
  buffConfigIO[10] = 23;			//FIOAnalog: setting FIO0-3 as analog, FIO4-7 as digital (binary0$
  buffConfigIO[11] = 0;			 //EIOAnalog : Not setting anything

  uint8 buffConfigTimer[10];
  buffConfigTimer[1] = (uint8)(0xF8);  //command byte
  buffConfigTimer[2] = (uint8)(0x02);  //number of data words
  buffConfigTimer[3] = (uint8)(0x0A);  //extended command number
  buffConfigTimer[6] = (uint8)(0x00);  //reserved
  buffConfigTimer[7] = (uint8)(0x00);  //reserved
  buffConfigTimer[8] = (uint8)(0x80);  //1000 0000
  buffConfigTimer[9] = (uint8)(0x00);

  uint8 buffFeedback[12];
  buffFeedback[1] = 0xF8;  //command byte
  buffFeedback[2] = 3;	 //number of data words (0.5 + 2 for Timer0Config + .5 for padding)
  buffFeedback[3] = 0;	 //Extended command number
  buffFeedback[6] = 0;	 //echo
  buffFeedback[7] = 43;	// IOType = 43 (Timer0Config)
  buffFeedback[8] = 0;	 //TimerMode = 0 (16-bit PWM output)
  buffFeedback[9] = 0;	 //Value LSB
  buffFeedback[10] = 192;  //Value MSB
  buffFeedback[11] = 0;	//padding

}
However the first call receives an error (msg 97 PIN_CONFIGURED_FOR_ANALOG). How is this possible if try to set the port during this call?
The 2nd and 3rd call work without any error (not completly sure about the 3rd one, because I couldnt find an answer sent by LJ) but there is no measureable signal output at FIO4.

Do you have any example to show me how to trigger a signal like every 10ms for a duration of 5ms or something close? Thanks in advance!

#6 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 October 2012 - 12:55 PM

You will want to set buffConfigIO[10] to 15 (b00001111), not 23 (b00010111). You are currently setting FIO4 to analog and enabling timer 0 on FIO04, causing the PIN_CONFIGURED_FOR_ANALOG error. Timer lines need to be digital. As for the timer settings for your trigger, I'll have someone else from around here respond back to you on that.

#7 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 25 October 2012 - 04:37 PM

Do you mean you want a 100Hz signal with 50% duty-cycle? If so, you can set the PWM frequency to 105 (~ 9.557 ms) by setting your timer clock to 48 MHz/Divisor with a divisor of 7 ( (48000000/7)/65536 = 105 ). So set:
buffConfigTimer[8] = (uint8)(0x86);  //b1000 0110
buffConfigTimer[9] = 7;
To set 5 ms of the ~10 ms to be output high, set the PWM16 value to 31215:
buffFeedback[9] = 239;	 //Value LSB
buffFeedback[10] = 121;  //Value MSB
The timer clock (in sec) * PWM16 value = sec the output will be low, or 1/(48000000/7) * 31215 = .004557 s with our settings. So out of the .009557 s PWM period, about .005 s (.009557 - .004557) will be output high.

Refer to this section in the User's Guide for documentation on PWM16:

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

#8 gnasen

gnasen
  • Members
  • 3 posts

Posted 26 October 2012 - 05:17 AM

Thank you very much for your fast help, Everything works now even with variable timings as expected!


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users