Need Arduino Compatible C++ Library from c; Reciprocal Frequency Measurement using Time Stamps

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok

This topic has a solution.

AVR Rocks but can be Bricked too smiley

Last Edited: Fri. Sep 15, 2017 - 06:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1/period = frequency
.
Has something changed?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

frequency is measured by

final_freq_measured=(float)((float)F_CPU/(float)(final_pulse_counted));

 

The problem is;

i need arduino ported version of

my_freq_stamper_rev1_ardmega2560.h
my_freq_stamper_rev1_ardmega2560.c

THese above are c version of my library to measure frequency.

and it works flawlessly accurate.

 

from Highest as 70KHz down to 0.001Hz (and anything less is 0Hz) ;

my code works in c

but i want to port these from c version to arduino version.

 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I posted my c code because it will help and saves a lot of time for community... i need arduino compatible version of my library...

AVR Rocks but can be Bricked too smiley

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engineer.pk wrote:
I want to shift to c++

The do that. By learning C++.

 

engineer.pk wrote:
make my library arduino compatible

If your code is legal and working C, then it is already "Arduino compatible". Bottom line is that the Arduino "core" is written in C++, and so are many of the "modules". But nothing stops you from calling C code from your init() and loop() functions in your Arduino "sketch". C code can be called from C++.

 

engineer.pk wrote:
i did tried to add extern "C" stuff but not working in arduino environment.

It is very likely you did something wrong. As I said, it is quite possible to call C code from C++.

 

engineer.pk wrote:
ineed c and header files if some one have skills & time to translate it for me.....

What is the incentive? Why should anyone do this for you? What will be the license for the final work? Who will get credits?

 


 

You might increase your chances of anyone taking this  on of you tidy up your code. Here are some remarks:

 

  • You have variable names in ALL_CAPS. This is against  all C/C++ conventions I know of. ALL_CAPS are only used for macro symbols.
     
  • Your indentation is a mess.
     
  • You have
    	++capt;		// capt will be keep track of how many times capture ISR is called
    	//value of capt; after 1st capt=1'b 0000 0001; after 2nd capt=1'b 0000 0010;

    but I don't understand what you're trying to say with the second comment.
     

  • You have this comment:
     

    // AFTER SENDING instant command for motor();

    but there is no other mention of "motor" in your code. The comment makes no sense at all.
     

  • You do
     

    pulse_counted=4294967295;

    Show that you are skilled C programmer. Don't use magic literal numbers. You have limits.h for this stuff!
     

  • You have this comment:
     

    //outer gating loop for PID,

    "PID"? No mention of it anywhere else!

And this is a start. There's more..

 

Frankly, it's a mess.

 

No skilled C/C++ programmer will likely want to touch your code without cleaning it up. And after that, the end result is more a work of that person than you, so the bulk of the credit should go to the person cleaning up and porting to C++.

 

I assume you want some credit/reputation for this. If so: I advise you to clean up the code to make it look like a first class piece of C code. Then try to draw interest from others to port it to C++. 

 

Also, write a high-level description of the algorithm you have implemented.

 

Sorry for not having a more merry response for you - but that's how it is..

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Fri. Sep 15, 2017 - 06:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok Thanks.

 

AVR Rocks but can be Bricked too smiley

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The problem is;

i need arduino ported version of

my_freq_stamper_rev1_ardmega2560.h
my_freq_stamper_rev1_ardmega2560.c

THese above are c version of my library to measure frequency.

and it works flawlessly accurate.

 

Rename  my_freq_stamper_rev1_ardmega2560.c

to my_freq_stamper_rev1_ardmega2560.ino

In main.ino #include  my_freq_stamper_rev1_ardmega2560.h