Quantcast
Channel: Counter/Timer topics
Viewing all 1271 articles
Browse latest View live

make a xy graph with three data from cluster and tick count

$
0
0

Hi everyone.I have an issue with combining time counter and array of clusters to the xy graph. While three data are being collected, I want to write it into a xy graph seperately with the time counter. I also put my VI and png file. Please help.


STM32F4 - Reading general purpose timer count

$
0
0

There seems to be a little bit of trouble when I run this code.

The situation is following,I'm using the STM32F4 HAL library on an emulated [in QEMU] STM32F4 Discovery board, and trying to configure TIM2 (general purpose timer) and read its' count register (without an interrupt). Currently I'm always getting 0 when attempting to read the timer counter with

uint32_t count = __HAL_TIM_GetCounter(&hTim2);

I don't want to move on to using an interrupt just yet, until I get this step working. Taking it step by step.

Here's how I configured the timer so far:

__initialize_hardware.c

__TIM2_CLK_ENABLE();// Enable the TIM2 clock// ...Timer_Init();

timer.h

TIM_HandleTypeDef hTim2;

timer.c

#include"timer.h"voidTimer_Init(void){
    hTim2.Instance= TIM2;
    hTim2.Init.Prescaler=40000;
    hTim2.Init.CounterMode= TIM_COUNTERMODE_UP;
    hTim2.Init.Period=500;
    hTim2.Init.ClockDivision= TIM_CLOCKDIVISION_DIV1;
    HAL_TIM_Base_Init(&hTim2);

    HAL_TIM_Base_Start(&hTim2);// Trying to start the base counter}void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base){if(htim_base->Instance== TIM2){
        __TIM2_CLK_ENABLE();}}void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base){if(htim_base->Instance== TIM2){
        __TIM2_CLK_DISABLE();}}

then in main.c

int main(int argc,char* argv[]){while(1){uint32_t count = __HAL_TIM_GetCounter(&hTim2);
        trace_printf("%lu\n", count);}}

I'm always getting 0 in count above, not sure why? Can anyone please offer some advice for my program?

Thanks

Synchronizing 4 Counters to Countdown Backwards 1 at a Time

$
0
0

I'm new to using multisim and was trying to get four timers to countdown 1 at a time from 9 to 0. Counter 1 9 to 0 then shuts off then the counter 2 does the same then to counter 3 then 4.

STM32F1 troubles with a timer

$
0
0

Today I'm working on my program and having some troubles with setting up a 1 second timer on STM32F103 mcu.

I have set Timer 2 to have a prescaler of 1099 and a period of 65514, so I'm expecting to have a 1 second interrupt rate: 72MHz/1099/65514 = 1Hz.

Yet in reality I get the first interrupt before even finishing the timer configuration routine (not a big concern at the moment), the next interrupt occurs after 1000ms as expected, the next interrupt occurs after 322ms, and the next after 32ms and the next after 590ms. (these were measured according to the systick timer which I have running at 1ms).

It seems pretty random, what's going on ?

Here is part of the relevant code:

void RCC_Configuration(){
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA |
                        RCC_APB2Periph_GPIOB |
                        RCC_APB2Periph_AFIO  |
                        RCC_APB2Periph_USART1, ENABLE);

RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM3 |
                        RCC_APB1Periph_TIM2, ENABLE);}voidTimer2_4_5_Configuration(){
TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Prescaler =(1099-1);
TIM_TimeBaseStructure.TIM_Period =(65514-1);


TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

TIM_Cmd(TIM2, ENABLE);}void NVIC_Configuration (){
NVIC_InitTypeDef NVIC_InitStructure;

NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority =1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);}void TIM2_IRQHandler(){
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
GPIOA->ODR ^= GPIO_Pin_2;}

EDIT: I managed to get this to work, I did a silly mistake in the rest of my code. I have used the same pin for something else forgot to comment the line, oopsy.

The led on pin 2 toggles at 1Hz as intended, but a new question arises:

I have set a breakpoint at the pin toggle line in the TIM interrupt handler and it seems it fires up at random times as stated above. But when I remove the breakpoint the led toggles as intended.

What's going on ?

P.S - I'm using CooCox IDE.

Thanks all advices.

How to read the output from a digital counter using python?

$
0
0

I am able to read the counter output from labview but when I tried to implement the following code in python I am unable to read the counter. I am in urgent need to solve this problem could someone please help out?  

 

Python code: 

import nidaqmx

from nidaqmx.constants import AcquisitionType, TaskMode, CountDirection, Edge
from nidaqmx._task_modules.channels.ci_channel import CIChannel
from nidaqmx._task_modules.channel_collection import ChannelCollection

 

with nidaqmx.Task() as task:
#create virtual channel
task.ci_channels.add_ci_count_edges_chan('Dev1/ctr1', initial_count=0, edge=Edge.RISING, count_direction=CountDirection.COUNT_UP)
task.read()

 

I get the following error

 

Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\_lib.py", line 139, in __getattr__
cfunc = getattr(self._library, function)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 361, in __getattr__
func = self.__getitem__(name)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\ctypes\__init__.py", line 366, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'DAQmxReadCounterU32Ex' not found

 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\....\TrialRead_DigSensor.py", line 33, in <module>
a= task.read()
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\task.py", line 686, in read
self._handle, data, number_of_samples_per_channel, timeout)
File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\_task_modules\read_functions.py", line 359, in _read_counter_u_32_ex
cfunc = lib_importer.windll.DAQmxReadCounterU32Ex


File "C:\Users\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nidaqmx\_lib.py", line 149, in __getattr__
'version of NI-DAQmx.'.format(function))
nidaqmx._lib.DaqFunctionNotSupportedError: The NI-DAQmx function "DAQmxReadCounterU32Ex" is not supported in this version of NI-DAQmx. Visit ni.com/downloads to upgrade your version of NI-DAQmx.

 

 

Movie Predator Gauntlet Countdown Timer

$
0
0

For an extra credit side project, my lab partner and I were trying to create a circuit in Multisim of the gauntlet countdown timer from the movie Predator. Anyone done this before? Or anyone know how to do this?

Low duty cycle square wave input

$
0
0

Hi there,

 

I need to have a VI that can receive a squarewave input up to around 500 Hz, (I actually expect to be around 400 Hz max) but I don't yet know what the duty cycle will be. The high time of the wave could be as short as 10 us or so, because I am actually getting the squarewave from a shaft rotating upwards of 20,000 rpm, and I don't know how big the contact on the shaft is yet. I have a very simple program that can display the frequency that my NI USB 6343 is reading on an analog input, but when I test my VI it seems like below around 400 us high time I no longer display the correct frequency. There must be a way to either modify my VI or use another implementation entirely using Counters?

 

My simple VI is attached

thanks!!

 

 

Counter Measurument Problem

$
0
0

Hi

 

I have a CompactRIO counter module. I am using it to make period measurument. I am also using a third-party hardware that sends me RPM. The same sensor is connected to either CompactRIO or the third-part hardware.

 

I know that the resolution of CompactRIO module is bigger than the other device. But when I look at the measurument results, I see that at low frequencies there is big measurument difference in between the two devices.(for example -+500 RPM) When the speed of engine increases, the difference decreases (for example -+200 RPM)

 

That should not be, there is something wrong. But I could not figure out.

 

Note: Input filter of CompactRIO counter is set to 1 ns. (I did not try the other options except 1 ns)

 

Any idea??


Pulse frequency Vortex meter

$
0
0

Hi everyone,

 

I am trying to read the output (4-20mA pulse) of a vortex meter system to regulate an air flow rate.

The old system is using a display 415A.10E from contrec and the reading is working fine.

I am trying to read this same pulse signal with NI modules but I am stuck, after trying different solution none gave me a stable signal. 

 

I have two module I tried to use, NI-9361 and NI-9401.

Since it is my first time trying to read a pulse signal via labview I turn to you for pointers !

 

Can someone help me? How to configure the Daqmx routine? is there some special conversion needed? 

 

Thanks for your help

Yann

 

Frequency and Duty Cycle measurement with NI 9361

$
0
0

Hello,

 

in the LabVIEW examples there is a Counter - Read Pulse Duty Cycle and Frequency (Continuous).vi

 

As in this VI, I want to use the Counter 1D Pulse Freq 1Chan NSamp type reading, so that I get a Cluster with frequency and duty cycle.

 

I have a NI 9361 module. If I select the physical channel "NI_9361/ctr0" on the front Panel, I get an error -200431:

"Selected physical channel does not support the measurement type required by the virtual channel you are creating."

 

Can anybody tell me how to measure frequency and duty cycle of a PWM Signal using NI 9361?

Medidor de caudal por pulsos

$
0
0

Buenas tardes, estoy en un proyecto de facultad en el cual debo utilizar un medidor de caudal para sacar el flujo de una linea. El sensor que la universidad adquirió es Octave Polymer Ultrasonic Bulk Water meter y trajo consigo un modulo de salida de doble pulso (Open Drain dual output) Adjunto a continuación el esquema de conexión.

Captura.PNG

Como dispositivo tengo un MyDAQ y, por tratarse de pulsos, conecté el rojo y el verde a los puertos digitales 0 y 1 de mi MyDAQ.

 El problema en cuestión es que no estoy logrando levantar los datos con nada. He intentado empezar por hacer un programa que me cuente solo la cantidad de pulsos que se van dando, pero no he obtenido resultados. He hecho decenas de programas, seguido tutoriales de youtube, casos parecidos que se plantearon en este foro y también seguido los ejemplos presentes en la ayuda de labview, como «counter edges», por ejemplo, pero tampoco he podido obtener resultados. Lo más próximo que he logrado a algo ha sido con el ejemplo de count edges, pero me daba números que yo entiendo disparatados ya que, en cuestión de segundos el contador me mostraba un valor de cientos de miles, además de que al variar la frecuencia de la bomba (y por tanto el caudal) el ritmo con el que aumentaba no surtía efecto alguno. 

Intente con varios casos del DAQ assistant también, pero tampoco funcionó.

 

El caudalímetro funciona bien, ya que tiene una tapa digital y esa anda a la perfección. También he probado si llegan al MyDAQ los pulsos y sí, la prueba en la parte de configuración del DAQ assistant me los muestra, pero no estoy logrando levantar los pulsos mediante la programación.

 

Espero alguien pueda guiarme en este problema.

 

Desde ya, muchas gracias.

Atte,

 

Matías A.

Buffered gated event counting

$
0
0

Dear all,

 

I'm trying to add gating to buffered event counting. The latter works, however, making it gated gives errors. Since turning the counter on and off seems simple enough, I hope I'm missing something. Gating would be in the order of microseconds, while sampling is in the order of milliseconds.

 

Below the example I tried, which gives the error: Pause trigger is only valid for event counting if sample clock is not used.

 

TaskHandle task_out;
DAQmxCreateTask( "", &task_out );
DAQmxCreateCOPulseChanFreq( task_out, "dev1/ctr3", "", DAQmx_Val_Hz, DAQmx_Val_Low, 0, 20.0, 0.5 );
DAQmxCfgImplicitTiming( task_out, DAQmx_Val_ContSamps, 2 );
DAQmxStartTask( task_out );

 

TaskHandle task_in;
DAQmxCreateTask( "", &task_in );
DAQmxCreateCICountEdgesChan( task_in, "dev1/ctr1", "", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp );

 

DAQmxSetPauseTrigType( task_in, DAQmx_Val_DigLvl );

DAQmxSetDigLvlPauseTrigSrc( task_in, "dev1/ctr1" );

DAQmxSetDigLvlPauseTrigWhen( task_in, DAQmx_Val_Low );

 

DAQmxCfgSampClkTiming( task_in, "/dev1/ctr3InternalOutput", 20.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 2 );

 

DAQmxStartTask( task_in );

// Reading

DAQmxStopTask( task_in );

DAQmxStopTask( task_out );

 

Does anyone know whether there is a different way to do this, or would I have to put a switch at the input of the counted signal?

 

Kind regards

 

(Using PCI 6601, windows 7, version 17.0.0 for NIDAQmx, c++)

 

PS One post seemed to ask something similar (post title being 'Buffered gated event counting'), but for the application in that post, buffered gated event counting was not required and a different kind of measurement was proposed.

Counter pulse generation issues when synchronizing with analog output sample clock

$
0
0

Hello,

 

The device I am using is a NI USB-6229 USB. I have written a program that produces a finite sine wave on the analog output that consists of 200ms worth of samples. In addition to the analog output, I am trying to turn on 2 counters for the duration that the analog output is active.

 

I experience an issue depending on how many high ticks I define for the counter. The counter output works as expected as long as the number of high ticks is less than the number of samples I am generating for the sine wave. For example, if I configure the counters to use a number of ticks equal to 100ms I get the following output on my oscilloscope.

 

Note: Analog output shown in yellow, counter 0 is D0, counter 1 is D1, & D2 is my start trigger signal.

scope_3.png

 

 

The counter output does not work as expected if the number of high ticks is equal to the number of samples I am generating for the sine wave. For example, if I configure the counters to use a number of ticks equal to 200ms, I get the following output on my oscilloscope.scope_4.png

 

 

The expected behavior is that the counters would have been set to low at the same time that analog output 0 returns to 0V. But, one will notice that D0 & D1 (counter 0 & counter 1 respectively) stay high for longer than expected. If we zoom in, in-time on oscilloscope we can see that counter 0 turns off roughly 5ms after the analog output returns to 0 (this is shown in the screenshot below). We can also see that counter 1 turns off roughly 1ms after counter 0 returns to 0.scope_5.png

 

 

This behavior is not acceptable for my application. I need to get the analog output & counters synchronized such that the counters turn off when the analog output is complete.

 

I have attached a sample project that demonstrates this behavior.

 

How can I solve this issue?

How to use 4 counters in NI 9401 & cDAQ -9178

$
0
0

Hi frds , 

I am new LabVIEW i have to generate 6 channel PWM pulse for my application in one click if it possible to generate using 9401 with cDAQ 9178. I tried one example programs for counter output but it's always generating one one channel but i tried for selecting array of channels it's giving error

DAQmxSetCIEncoderAInputTerm arguments

$
0
0

I am trying to translate this .NET command to it's c equivalent:

 

myCounterTask->CIChannels[0]->EncoderAInputTerminal = "/Dev1/PFI0";

 

The c function would be:

 

DAQmxSetCIEncoderAInputTerm(myCounterTaskHandle, "/Dev1/PFI0", const char *data);

 

Except I have no idea what "data" refers to.  The .NET equivalent has no such argument and there is no obvious data associated with this operation beyond the channel name.  I tried looking it up in the NI documentation, but it is totally useless (just a copy and paste from the header file with no actual information):

http://zone.ni.com/reference/en-XX/help/370471AA-01/mxcprop/func219d/

 

Anyone used this function before and know what the last argument should be? 


Max number of angular encoders I can simultaneous read using a 9174 chassis and 2x9411 modules?

$
0
0

This is the bottomline theoretical question:

How many simultaneous angular measurements can I have using 2 separate 9411 counter modules which exist in a 9174 (4 slot) chassis?

(or to re-phrase)

Am I limited to a single angular encoder task (with a single counter channel in it) on 9174 chassis even if I have multiple counter modules?

 

Below are the details:

I am, ideally, trying to simultaneously measure torque and angle from 4 axis of rotation at the same time. (I also have one 9239 module for reading the analog torque sensor output.) I will be OK, even if I can read them 2-by-2.


The torque channels can live in a single AI task and I can sample them (hardware timed) together without problems. And I can use the same AI sample clock to sample the encoder reading. But I cannot read 2 encoders simultaneously. They cannot be put in a single task and I cannot start 2 separate counter tasks simultaneously.

I can start the AI (with all 4 channels inside) and the first counter task (only counter-0 of first 9411 inside) without problems. But when I also start the second counter task (only counter-0 of second 9411 inside) I get an error saying "the resource is reserved already". I do not know which resource it is complaining about. The 2 counters/encoders/tasks I want to read from are on 2 separate modules. But for some reason it does not allow that.

 

Is there a way of getting what I need with this hardware configuration, of do I need another counter module like 9361?

Measuring continuously counter edge separation

$
0
0

Dear all,

 

I'm trying to measure continuously the separtion between pulses on a pulse train coming from a measurment device.

For that I'm using the source "ctr0" (physical channel PFI8) of my NI pcie 6351 card (X serie). The train amplitude is around 3V with an aproximate frequency of 500Hz.

I wrote a C++ program using the DAQmx library and everything is fine on that front, I don't get any error when calling any DAQ function.

here is the related part of my code :

error = DAQmxCreateTask("", &coTask);
DAQErrChk (error, "coTask DAQmxCreateTask");

error = DAQmxCreateCITwoEdgeSepChan(coTask, "dev1/ctr0", "", 10.0e-8, 1, DAQmx_Val_Seconds,
                                        DAQmx_Val_Rising, DAQmx_Val_Rising, NULL);
    DAQErrChk (error, "coTask DAQmxCreateCITwoEdgeSepChan");

error = DAQmxCfgImplicitTiming (coTask, DAQmx_Val_ContSamps, 1000);
    DAQErrChk (error, "coTask  DAQmxCfgImplicitTiming");

error = DAQmxStartTask(coTask);
        DAQErrChk (error, "coTask DAQmxStartTask");

 error = DAQmxReadCounterScalarF64(coTask,1 ,&data,0);
    qDebug()<<data;

I linked the

DAQmxReadCounterScalarF64

function to a button callback so I can check at reguler interval the last measurement. the problem is : there is no measurement. Each call to the measure function hit the time out.

I also tried to measure the train pulse frequency with no success whatsoever.

I'm starting to think that the amplitude of the pulses is too low (~3V) and the task is expecting a classic 5V TTL but I haven't find any method allowing me to define the amplitude of the pulse.

I tried:

 DAQmxSetDILogicFamily(coTask, "dev1/ctr0", DAQmx_Val_2point5V)

but apparently, this method doesn't apply for counter.

The weird thing is that I can count the number of pulses in the train.

Any help would be welcome!

many Thanks in advance

 

Creating Derived Clocks on a cRIO-9068

$
0
0

I have a cRIO-9068 and I am creating a project that is designed to run entirely on the FPGA. I have a base FPGA clock of 40 MHz. I need to create a series of derived clocks (10Hz, 100Hz, 1000Hz and 10,000Hz) each one to drive the polling of a different type of senor plugged into various input modules. However I cannot get to the point of polling the modules as I am unable to perform the most basic task of setting up and creating the clocks that I need to use. 

 

When I try to create a derived clock It won't let me create anything below 4.69 MHz (See image): 

 

Capture.PNG

 

Method used: (Chasis -> FPGA Target -> 40 MHz Onboard Clock -> (right click) New FPGA Derrived Clock. 

I tried this method to ensure all the clocks would be synchronized. 

 

Thanks, 

Mat

Connecting the PXI6608 to the BNC2110

$
0
0

Hi all,

 

I am trying to use the PXI6608 to generate precise pulses. Is it possible to connect the PXI6608 to the BNC2110? I have both, and I am using the cable RS6868 to make the connection. However, the power light indicator is not lighting. Does anybody have an idea about the problem?

 

Thank you,

 

JJJJeb

Counter Pause on Digital Level; resume on user input

$
0
0

Hi, rotating a sample wheel with stepper driven by continuous counter output.  Each position of sx wheel has a key for a photo-interrupter.  When interrupted, counter pauses.  

I desire to 'override' the pause trigger with a user input control 'resume' but immediately revert to triggered stop at next sx position.

 

Attached is a small snippet that shows the pause setup I have.  The 'Data Changed' vi is for the user to change frequency or rotation on-the-fly if needed.

 

Suggestions on how to accomplish would be appreciated.

Thanks,
Chris

Viewing all 1271 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>