Go Down

Topic: pulse width / period measurment with offset (Read 1 time) previous topic - next topic

country4life89

Mar 08, 2018, 05:03 am Last Edit: Mar 08, 2018, 03:02 pm by robtillaart
Hello all!

I would like to start off by saying I am not asking anyone to spend their time writing code for me for free. I will and have done research and just cant wrap my head around this.

Having said that here is what i am trying to do. I experiment with motors, generators and basically electromechanical devices. Up till now i have used many other means and circuits to pulse coils or connect coils at certain intervals but i have to design something new for every machine. One of the key aspects of the generators and such that i work with is a very clean make and break contact (brushes or relays) because transistors and mosfets take sometimes multiple microsends to be fully on / fully off and that does not suit the experiments.  instead of making complicated contacts or circuits to have a switch at a certain point i want to make a controller that can sense the location of a magnet on a flywheel and be able to use the data to turn on or off relays at a given point. Another thing that is important is to be able to display the data on an oled because the entire point is to be able to adjust parameters and be able to correlate those parameters to the effects in the machine.

main example of what I am trying to do is this. I have a pulse motor with a rotor with 4 magnets, and one drive coil. I want to be able to know when the magnet is at Top Dead Center (TDC) meaning exactly at the center of the coil. From there I want to be able to offset a value so that i can make a relay close at  (for example) 3 degrees after TDC untill a max of half the period (half way between the magnets). I need that to be adjustable "on the fly" so to be able to adjust and see the effects that is has on the motor. The problems I have a trouble wrapping my head around are: 1 I dont really care about the "speed up" part, seeing as when the motor is accelerating to top speed every revolution the pulse width and period will be different until they level out. but even at top speed if i change something that causes acceleration if the acceleration is a lot then I have to measure calculate and adjust the timing "all" between the magnets. given the desire to have a 4 magnet rotor with a top speed of 4000 max that is a period of 3.759 miliseconds. in that amount of time i need to calculate the pulse width to know where the center of the magnet is (width /2 ) use that to set a value for TDC and have an offset for how far from TDC i want to turn on the switch and how long the switch will stay on. SO basically it is a must to be able to do everything measurement wise within that time frame. The motor will "probably" have a max of 2500 rpm but i am going with 4000 to leave room for the unexpected. #2 because i need to display the results on an oled I am wondering if i should use two linked arduinos with one doing the sensor readings and relay that information to a second which will do the calculation and switching. That is because i simly cannot think of a way to figure out how long it takes for the code to execute therefore I have no idea if 3.759 miliseconds would be enough time. That also leads to the fact that if i want the switch to happen only a few degrees past TDC there would only be 41.76 microseconds (at theoretical top speed) to calculate per degree away from TDC so if i wanted to switch on a coil when the magnet is 2 degrees past TDC i would only have roughly 82 microseconds to sense the magnet (rising pulse on an interrupt from a hall sensor) add 1/2 the previous pulse width to find TDC add the offset so it turns on the coil at 2 degrees and use the previous period measurment to adjust the "on time" of the coil so it turns off at a variable amount between TDC and half the period.

So, what I am thinking of is this: If I use one arduino with an interrupt to set a Micros() value (lets say T1) when the hall sensor senses a magnet (rising edge), and senses when the magnet is past (T2 - falling edge) and the next magnet (T3 next rising edge) . I can relay those values to the second arduno to be the "calculator", "display" and the "output" and use  T3 - T1 to find the period....T2 - T1 to find the pulse width which would leave the first arduino alone and let it sense everything precisely with basically only the interrupt to set the values and the IIC code to relay the data values to a second arduno. the second arduino would do the calculations and set the output values of TDC + offset to turn on the relay at a variable point and TDC + some variable to turn off the relay at a certain point, and also update the oled wich I only need updated every second or so. So does this sound feasible or am i completely barking up the wrong arduino?

Like i said before. I will do my research, But if anyone sees a problem with this idea or has ANY pointers on how to implement this in an easy fashion I would GREATLY appreciate any input.


At the current time I have a sketch I have built up be copying sections from multiple others to simply be able to read a hall sensor and find the period and calculate rpm. I believe it calculates based on a 2 pulse per revolution rotor, but that's simply because i am more focused on the other aspects and just haven't modified it for a 4 magnet rotor. when I can figure out whether i will need two arduinos or if it can be done with one i will write up a new code and post it so anybody that is feeling helpful can tell me if i am being an idiot. Thank you in advance to anybody that can help me think this through more clearly!

the current simple sketch for rpm measurment is this
Code: [Select]
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_MOSI   9
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define SSD1306_LCDHEIGHT 64
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

 int refsig = 200; //for converting the analog signal coming from hall sensor to digital through arduino code
 int val;//the digital value of the incoming analog signals
 int prev_val = 0;
 int t, cur_t; //time variables
 
void setup() {
 Serial.begin(115200);
 pinMode(A0, INPUT);
 display.begin(SSD1306_SWITCHCAPVCC);
 
  display.display();
  delay(2000);

 // Clear the buffer.
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.setTextColor(WHITE);

}

void loop() {
 
  int sig = analogRead(A0); //read raw value of hall sensor
   if (sig > refsig) val = HIGH; //when value of hall sensor is above refsig sets val as digital high
   else val = LOW;  // if not above refsig sets val to digital low
   if (prev_val == 0 && val == 1) { //if the prev_val was low and val goes high it has sensed the rising edge
   cur_t = micros();
     
  display.setCursor(0, 0);
  display.print("RPM: ");
  display.println(1000000 * 60 / (cur_t - t)); //print the rpm
  display.display(); //you have to tell the display to...display
  delayMicroseconds(2);
  display.clearDisplay();
  t = micros(); // sets time so the next loop around after reading the value cur_t - t =time elapsed between pulses
   }
}

Moderator added code tags

Robin2

#1
Mar 08, 2018, 09:13 am Last Edit: Mar 08, 2018, 09:14 am by Robin2
Your Post is very long so I may have missed something.

3.7 millisecs is a very long time for an Arduino

I don't understand why it is necessary to detect TDC specifically. Isn't it sufficient to detect some event before TDC that is a known time prior to TDC? Wouldn't that leave more time for your calculations?

If you want to measure speed or detect an event with precision then don't use analogRead() as it is a relatively slow function - takes a minimum of about 100 microsecs. Instead arrange your sensor to produce an digital pulse and detect it with an interrupt. See attachInterrupt() in the Reference section.

This is an extract from code I use to detect the speed of a small DC motor. It works fine up to 16,000 RPM and probably much faster.
Code: [Select]
volatile unsigned long isrMicros;
unsigned long latestIsrMicros;
unsigned long previousIsrMicros;
volatile boolean newISR = false;


void loop() {
   if (newISR == true) {
     previousIsrMicros = latestIsrMicros; // save the old value
     noInterrupts(); // pause interrupts while we get the new value
        latestIsrMicros = isrMicros;
        newISR = false;
     interrupts();
     microsThisRev = latestIsrMicros - previousIsrMicos;
}

void myISR() {
   isrMicros = micros();
   newISR = true;
}


It would make it a great deal easier to understand your requirement if you can post a diagram that shows the timing requirement.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

country4life89

Thank you for the reply! I will try to write a simpler " to the point " explanation shortly along with a diagram to better explain what I'm trying to do.  Again thank you for the input.

wvmarle

So you want to use relays because the rising edge of a MOSFET is too long, right?

Now the problem you will run into is the reaction time of the relay. To time the moment the pulse happens, you have to know how much in advance to power the relay coil. This will be more than the few microseconds you have a problem with in the MOSFET scenario.

That said, MOSFETs can switch really really fast. Just think of the many such transistors that make up the microprocessor of the computer you're working on, those can work with several GHz clock speeds. For your application, choose one with a very low gate capacitance, and don't put a resistor between the Arduino pin and the gate. You'll easily get switching speeds down to the nanoseconds.

How about the CMUDM7001TR which has a CISS of 9 pF, and a gate capacitance of 0.57 nC @ 4.5V. Or the CSD15380F3T with a CISS of 10.5 pF, but a gate capacitance of a mere 0.281 nC @ 10V. Those you should be able to switch fully on within 1-2 ns, with the 40 mA the Arduino can supply (the actual edge rise will be much faster, as much of this time is used to charge the gate to it's threshold value). Not likely you will see much if any difference with a relay switch, which also has to deal with stray capacitance.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

wvmarle

There is no such thing as instant rise time. That's impossible. Stray capacitance and inductance of your wires alone prevent that from happening, that's just real world physics at play.

A quick Google search showed that the reaction time of relays is typically 5-15 ms. So that's 7 orders of magnitude greater than the time scale you want to work with. You may be able to find faster relays but physics get in the way of moving those contacts that much faster.

You mention you have periods of 3.759 ms, which is shorter than even the on or off switching time of a relay. A complete on/off cycle takes double the time given above, so 10-30 ms. This alone makes an electromechanical relay a no-go for your application.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

MorganS

#5
Mar 08, 2018, 06:03 pm Last Edit: Mar 08, 2018, 06:03 pm by MorganS
Even if you can start the relay moving in advance of the time you want it to be closed or opened, the time it takes for the contacts to go from first touch to fully closed will be hundreds of times longer than the 1-2 nanoseconds possible with a MOSFET.

For most practical puposes, 0.000000001 seconds is close enough to 0 seconds. You can never truly have zero switching time. If you really care, then some work with proper MOSFET drivers can deliver more than 20A into the MOSFET gate to charge it really quickly. That's a thousand times more current than the Arduino can manage on its own.

A couple of nanoseconds is right on the edge  of what you can meaningfully measure with a 100MHz scope. If you are seeing significant rise times with that equipment then something else is wrong.

Where is this code with delay(2) that you mention?

There are two ways of timing critical code in the Arduino. The easy way is to record the microseconds at the start and end of a loop which runs the code 1000 times over. Be careful that the compiler doesn't optimise away your code. The harder way is to disassemble the binary into readable assembler and count the instructions that the compiler produced for your critical section.This requies an instruction list for your exact chip to tell you how many clock cycles each different instruction uses.
"The problem is in the code you didn't post."

Paul_KD7HB

Both  my father and his father spent their lived trying to invent a perpetual motion machine. I detect the same here.

Paul

Robin2

I am working with ideas that Nikola Tesla was working with and it requires a 0 second (instant) rise time so even a few nanoseconds would negate the purpose of the project.
I thought you were going to provide a diagram to show the timing you require.

A 16MHz Arduino has a clock time of 62.5 ns so that is the very best precision that could be achieved. In practice I doubt if you will get 4 times that.

Does that rule out an Arduino altogether?

And you have still produced a huge single paragraph in your Reply #4. That sort of thing works fine in a novel. But it makes technical stuff very hard to comprehend. A good test is to read your text out loud and see if it can be understood (and you can only take a breath between paragraphs :) )

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

MorganS

Ok, I see the delayMicroseconds(2) now. That is a very poor way to use this display. Just display the data and don't clear it until you have new data.

Note that the fixed text like "RPM" should not be re-written to the display every time. Just update the parts of the display which actually change. Don't clear the whole display.

The Adafruit OLEDs I have used are relatively slow because they must write the whole screen in that display.display() method. The other methods are fast as they only update the Arduino memory. You never want to call .display() in timing-critical code.
"The problem is in the code you didn't post."

country4life89

#9
Mar 08, 2018, 07:04 pm Last Edit: Mar 08, 2018, 07:10 pm by country4life89
Both  my father and his father spent their lived trying to invent a perpetual motion machine. I detect the same here.

Paul
perpetual motion NO but over-unity has been proven without a doubt in certain electrical devices...so yes you know what I am working towards but no it is NOT perpetual motion. During the very very small time when a source is connected to a load BEFORE the electrons move ohms law does not work. After that very brief moment everything is calculated as normal per ohms law....also when current is flowing in an inductive load and the source is disconnected for a very brief moment the same happens in reverse and the coil becomes the "source". when done correctly it becomes an open thermodynamic system which absorbs energy from around the coil during those moments. Think of it like this, if you use a 20 volt drill and drill a hole into a dam then hook a generator/hydro plant to that you get more energy out of the damn then you put in to release that energy because mother nature provides the power via rain. In certain electrical systems, this can be used and an analogous way. you use a small input pulse to trigger an event that puts the coil into a state that allows it to absorb energy from something other than your source battery. There are systems that have been proven to do this by many many people...the problem is finding what gets the "most" extra energy into the system. Tesla called it radiant electricity. those moments have effects that can not be explained by current electrical theory. for instance, if you put a radio in a Faraday cage that is grounded no radio waves or RF of any kind should be able to get to the radio, but if you run one of these motors that cause these events you can hear ticks on the radio every time the contacts are connected or disconnected. along with many other weird effects. The current machine i am working on is based off of https://patents.google.com/patent/US6392370B1/en .

As for the code I think i confused the crap out of myself so i will sit down tonight and think it through again and test a few things and check back in with any questions. Thank you ALL for the input.


EDIT: I tried to upload a picture of a diagram i drew and the file is to large I am quite busy at the moment and will try to upload a smaller file size later this evening.

Robin2

those moments have effects that can not be explained by current electrical theory. for instance, if you put a radio in a Faraday cage that is grounded no radio waves or RF of any kind should be able to get to the radio, but if you run one of these motors that cause these events you can hear ticks on the radio every time the contacts are connected or disconnected.
Time to dig out my tin-foil hat  :)

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

country4life89

Time to dig out my tin-foil hat  :)

...R
If it goes through a Faraday cage your hat won't work!

If by that you are judging me as some whackjob because I am trying to study "known science" that could one day stop you from having to pay for gas in your car or an electric bill for your house ....by all means feel free to stand behind your right of free speech but I would ask one thing out of respect from human to human. Look into it. While keeping in mind....the world used to be flat, heavier than air flight could not happen, and many other things.

This stuff has been proven many times, it is not some theory. The only problem so far is taking something that puts out 150 percent what is put in and being able to scale it up. It absolutely works. But when you consider to have 10,000 watts "extra" you have to have a machine running at 20,000 watts input because when you make it self contained you must take 20,000 watts of the output and send it back to the input to be able to get that extra 10,000.

This is not the purpose of this post. I apologise about the paragraph / books. I have ADHD and it's hard to not just ramble. I will go back and edit my post and upload the diagram and try to have the "actual " code up as soon as I can. As I said that code I just pieced together mostly to test the oled because I have never used one.

country4life89

#12
Mar 09, 2018, 02:20 am Last Edit: Mar 09, 2018, 02:26 am by country4life89
 I am going to just try and keep everything to the point from here on out with diagrams and short paragraphs.

I don't understand why it is necessary to detect TDC specifically. Isn't it sufficient to detect some event before TDC that is a known time prior to TDC? Wouldn't that leave more time for your calculations?


The key aspect of the motor/generator that I currently want to run with this setup, is to have the drive coil turn on at a certain angle past TDC. I want this point to be variable so I can turn the coil on at a point between TDC and a few degrees later. Therefore I figured having a value of TDC and then adding an offset would be the easiest way of making that variable turn on point.

As the coil turns on it will push away the magnet. If left on past 45 degrees (in the diagram) then it would be counterproductive, because at that point it would begin to resist the magnet approaching from the other side. Therefore that is the MAX angle that the coil should ever be "on".

[/quote]
A quick Google search showed that the reaction time of relays is typically 5-15 ms. So that's 7 orders of magnitude greater than the time scale you want to work with. You may be able to find faster relays but physics get in the way of moving those contacts that much faster.
Thank you for that information, and yes that shoots the relay idea out of the equation. The "first touch" of the relay and abrupt disconnect was the main reason why I wanted to use relays but if its not possible then I will have to try and use mosfets. Tesla describes a time when he throws a switch (one of the knife switches they used then) in the instant that the connection was made a purple glow was seen around the wire which could not be accounted for by normal theory and had anomalous effects. Most experiments I have seen that produce that effect always had mechanical contacts (brushes or mechanical switches).

The reason I did not want to use mosfets is because those moments where the anomalous reaction shows up creates voltage spikes many magnitudes larger than the input voltage. So if i use a mosfet capable of switching 12 volts it could be subjected to spikes in the hundreds of volts. If I use mosfets rated for hundreds of volts they do not switch the 12 volts very well. I have completely fried many 50 volt rated mosfets and transistors on 12 volts with these machines. 

As for the code, and my last point, i can do whatever research is necessary to figure it out myself. To even begin that though, I need to figure out the feasibility of what switching method and the timing requirements of how to implement the values I need. I knew that relays took some time to turn on and honestly just assumed it was much less than what it is. So the thing I need to figure out is the best way to measure values so that I can have an adjustable on time of the coil at certain angles between the two dotted lines on the diagram.

I hope this is more clear and understandable and again I apologize for the rambling and length of my posts. Also thank you to everyone for all the input.

TomGeorge

There is no such thing as instant rise time. That's impossible. Stray capacitance and inductance of your wires alone prevent that from happening, that's just real world physics at play.

A quick Google search showed that the reaction time of relays is typically 5-15 ms. So that's 7 orders of magnitude greater than the time scale you want to work with. You may be able to find faster relays but physics get in the way of moving those contacts that much faster.

You mention you have periods of 3.759 ms, which is shorter than even the on or off switching time of a relay. A complete on/off cycle takes double the time given above, so 10-30 ms. This alone makes an electromechanical relay a no-go for your application.
The 5 to 15ms reaction time  will not be consistent for a particular relay, so you using a relay you have a built in deviation for each activation from what you want of  up to 15ms.
A MOSFET will be consistent and fast in its response.
Can you provide a diagram of your apparatus and a diagram/graph of the response you need from the timing circuit.
Can you please tell us your electronics, programming, Arduino, hardware experience?

Quote
perpetual motion NO but over-unity has been proven without a doubt in certain electrical devices...
so yes you know what I am working towards but no it is NOT perpetual motion.

During the very very small time when a source is connected to a load BEFORE the electrons move ohms law does not work.

After that very brief moment everything is calculated as normal per ohms law....
also when current is flowing in an inductive load and the source is disconnected for a very brief moment the same happens in reverse and the coil becomes the "source".

when done correctly it becomes an open thermodynamic system which absorbs energy from around the coil during those moments.

Think of it like this, if you use a 20 volt drill and drill a hole into a dam then hook a generator/hydro plant to that you get more energy out of the damn then you put in to release that energy because mother nature provides the power via rain.

In certain electrical systems, this can be used and an analogous way. you use a small input pulse to trigger an event that puts the coil into a state that allows it to absorb energy from something other than your source battery.

There are systems that have been proven to do this by many many people...the problem is finding what gets the "most" extra energy into the system.

Tesla called it radiant electricity. those moments have effects that can not be explained by current electrical theory.
for instance, if you put a radio in a Faraday cage that is grounded no radio waves or RF of any kind should be able to get to the radio,
but if you run one of these motors that cause these events you can hear ticks on the radio every time the contacts are connected or disconnected. along with many other weird effects. The current machine i am working on is based off of https://patents.google.com/patent/US6392370B1/en .
Quote
There are systems that have been proven to do this by many many people...the problem is finding what gets the "most" extra energy into the system.
[soapbox]
If you can get even 5% more energy out than you put in, then why isn't it available now?
5% would revolutionary.
1000W in out of my mains supply, (Easy) and the machine gives me an extra 50W, give it to me.
50W of extra LED lighting for free in a factory lighting situation for every 1000W, got to save money, so why aren't we seeing this now?
I appreciate that there has to be experimenters out there prepared to deviate from the norm, but the demonstrations that I have seen of over unity either;
  • use black boxes that are never disclosed.
  • show apparatus, but never any details on coil construction or circuit description.
  • use very unorthodox methods of measuring energy in and out, so efficiency/over unity calcs are not valid.
  • the demonstrator confuses Potential and Kinetic Energy.
  • has the fixation that back EMF from a disconnecting coil is extra energy coming out of the ether.

[/soapbox]
Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

TomGeorge

Everything runs on smoke, let the smoke out, it stops running....

Go Up