LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

count integer value of angle from encoder

Solved!
Go to solution

Hello,

 

I try to plot the pressure from one cylinder of an engine vs the cranckshaft angle. And do this for each motor cycle.

I want to plot the pressure value each degree which mean that I have 720 value per cycle because one mototor cycle corresponding of two rotation of the cranckshaft.

( I join a graph representing what I want to plot to simplify "pressure vs CAD")

 

My problem :

 

I have a 3600 ppr quadratic encoder which mean a precision of 0.1° but I'm just interresting by the entire value of angle.

So I plot the value of pressure only if the angle is an integer, apparently I miss a lot of them that's why I have a graph with 6 cycles instead of just one.

(see in attachment "my results")

 

I think it's because of a problem of timing with my loops on FPGA or on RT or both of them...

 

I'm open for each advices, examples or anything else who can help me

 

Best regards,

 

Simon

Download All
0 Kudos
Message 1 of 5
(2,576 Views)

Lucky for you, I have done an application just like this for natural gas pipeline engines. Yes, there are issues. You need to use a FIFO to buffer data from the FPGA and pass it to the host. You also need to only read data when an encoder DI changes from false to true (depending on how the pulse lines up with the Z pulse. Let me whip up an example and give you something you can visually see.

 

Do you need it to be able to adjust for TDC? Or, are you assuming Z is always at TDC?

0 Kudos
Message 2 of 5
(2,553 Views)
Solution
Accepted by topic author Simon_etu

I think you want something like this on the FPGA. You need to buffer your data. See if you can figure out the RT code to work with this. You basically want to read from the FIFO. Your problem now is you are reading a control, which means you can only read as fast as the RT can go. You are losing the benefit of the FPGAs speed. Your FPGA should read single point at a high rate. Your RT then reads multipoint chunks that are buffered up from the FPGA. My suggestion is to read from the FIFO 3600 elements at a time (one full revolution) on the RT side. This, of course depends on how fast the encoder is spinning. I would suggest determining the maximum RPM your system will run at, then set up your buffer size accordingly.

 

I have done FPGA, but I wouldn't quite call myself an expert yet. Others may come along with better ideas, but this is in general what I would do. Disclaimer: I didn't test or double check this work, so there definitely may be bugs. Also, this always waits for the Z pulse. In your application, you may want to wait for the Z pulse just one time, get the TDC offset, then just stay in the inner loop. I didn't know if you needed to sync up with the Z pulse every time or not. Either way, this should give you the general idea.

 

Edit: Haven't had my coffee yet. I should only be incrementing the count in the inner loop when I get a rising edge. And then, I should only be adding to the FIFO when the offset is greater than the TDC offset. Sorry, that mistake will cost you 20 minutes in compile time! I'm sure glad I put that disclaimer Smiley Tongue

 

 

 

 

0 Kudos
Message 3 of 5
(2,544 Views)

Thanks a lot for your help !

 

I used a FIFO and some parts of your examples and it works fine 🙂

I didn't really understand how worked a control and now I know why I had to use fifo !

 

Thanks again, your really helped me.

 

Simon

Message 4 of 5
(2,513 Views)

Glad I could help!

0 Kudos
Message 5 of 5
(2,505 Views)