error when configuring a 0.5Hz PWM signal on labjack t7 pro using lua | LabJack
 

error when configuring a 0.5Hz PWM signal on labjack t7 pro using lua

8 posts / 0 new
Last post
lee
leetho's picture
error when configuring a 0.5Hz PWM signal on labjack t7 pro using lua

Hi, i'm new to both programming and labjack. I recently been task with producing a pwm output signal with two sections. First 10 second is a 2Hz frequency, 1% duty cycle output signal. The next part is a 10 second 0.5Hz frequency, 55% duty cycle output signal. The problem is on the second part, which if i have a divisor of 4 and above, there will be no signal shown in the oscilloscope. If below 4, i will have wrong frequency and duty cycle. When i turn off the script, the output signal shown in the oscilloscope is correct. I want the output signal to be correct when turn on not off. How do i fix this issue? thank you, sorry for my bad english. 

Pwm file is my main script;

Pwm1 file only consist of the script for second part.

 

File Attachment: 
LabJack Support
labjack support's picture
Instead of disabling and re

Instead of disabling and re-enabling the PWM feature every interval please only update the DIO#_EF_CONFIG_A and DIO_EF_CLOCK#_ROLL_VALUE registers. You are currently restarting a PWM with a period of 2s every 1s, which should explain why the feature works correctly when you stop the script (the feature is left running but is not restarting every second).

lee
leetho's picture
Do you mean that i should

Do you mean that i should only put DIO#_EF_CONFIG_A and DIO_EF_CLOCK#_ROLL_VALUE inside the while loop and the other i leave it outside of the loop? As for the second part, i don t understand what you mean about how the script should works correctly when i stopped it.

LabJack Support
labjack support's picture
You only want to update those

You only want to update those two registers that control frequency and duty cycle in your loop, the rest is initial configuration that should be done before your loop. The problem you are seeing is caused by you restarting the feature every second in your script.

You said the oscilloscope output looks good once you disable the script; that is due to the fact that you were trying to restart the PWM once per second in your loop and when you stopped the script you stopped restarting the feature. The feature will continue to run uninterrupted after the script stops unless you explicitly disable the feature before you exit the script.

lee
leetho's picture
Hi, it works after i change

Hi, it works after i change the placement but im having modbus error 2566 when i initially starting up the script after reboot. I fix this by putting the DIO Enable inside the first part in the loop. But now im having  an issue with another modbus error 2566 when t = 6 during the second part of the loop, how do i fix this?

This is the script i ran.

File Attachment: 
lee
leetho's picture
Also i'm having another

Also i'm having another digital output signal with the PWM signal. The Digital output is high for the first 5 seconds then remain low for 10 seconds. There is a noticeable 1 second? delay on the PWM after the digital output becomes low. Is this cause by the modbus error 2566?  

LabJack Support
labjack support's picture
I was unable to reproduce any

I was unable to reproduce any issues enabling the feature before the loop, so I suspect that issue was due to some minor error where you were trying to set the EF_INDEX while the feature was enabled. What you are doing now seems good enough. You could try to move some more of the configuration for the first PWM settings outside of the loop again, but doing that should not have any real notable affect on your PWM output.

In your script I noticed that you write mbwrite(2000,1,0) --DIO1. This is incorrect, 2000 is the register for DIO0 and the second parameter is the data type constant, which should be 0 to indicate that you want to write a UINT16 value. 2001 is the address of DIO1, so your DIO write should look something like mbwrite(2001, 0, 0) if you intend to set DIO1 low.

When I tested your script I was seeing error 2565; is that the error you saw rather than 2566? We will look into that problem some more. The error 2565 does seem to be causing the feature to delay for approximately 1s before updating the duty cycle and PWM frequency.

lee
leetho's picture
Yes, the error is causing my

Yes, the error is causing my output to delay for 1 second. I notice it when i was looking at the output. I will include a video and picture to show my error and the output.