Author Topic: MP3 + speedometer?  (Read 37049 times)

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #60 on: October 04, 2014, 08:49:32 PM »
One more thing - even if I put my own hall sensor the problem will be the same.
I just put the regular 5V wire from the motor in the interrupt pin and it produces as well too much oscillation. May be this is because of the way they produce the 5 Volts...
So the new question is - how with a capacitor (which one and how to calculate), diode (which one) to prevent current to go back to the hall sensor and to mess with the controller and possibly a resistor to create flatten the signal coming from the hall sensor?

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #61 on: October 05, 2014, 12:06:00 AM »
A new discovery. I said "One more thing - even if I put my own hall sensor the problem will be the same."
So I wanted to verify that :) And blew three of my hall sensors (not of the bike) to discover that 5V from the controller are some other kind of 5 volts :)
What I did:
- I made my own circuity with 1 hall sensor and 10K resistor
- while the arduino is connected to 12V DC, I get 5V out from arduino to feed the hall sensor
- everything is working OK - a magnet changes the hall sensor's state
- now I disconnected the 5V feed from arduino and fed the hall sensor with "5V" wire from the controller (I measured with a multimeter that it really is 5 Volts)
- when I turned everything ON - the hall sensor stopped working - the magnet wasn't changing his state
- then I fed it again with arduino's 5 volts just to prove that the hall sensor is not working anymore - even with arduino's 5V now it wasn't changing its state.

Is there any explanation of this? What is so strange with the 5V coming from the controller that a) it is oscilating invisibly with 2500-5000Hz (only arduino detects that but a multimeter shows constant 5V) and b) it burns hall sensors?

Offline Morgen 3Eman

  • Confirmed
  • PhD. Magic
  • ******
  • Posts: 620
Re: MP III + speedometer?
« Reply #62 on: October 05, 2014, 01:04:48 AM »
Static electricity damage from handling is often the culprit when devices fail during handling.   Were you wearing a grounding strap, etc?

When your Arduino shows an oscillation, measure your input pin with your voltmeter set to AC.  What is the voltage displayed when a 5 or GND vdc signal is present? 

What happens when you connect the Arduino pin you are using for your input to +5 or GND with a resistor?  Does is read a frequency?  Again, are you using edge interrupts or level interrups?   

Dennis

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #63 on: October 05, 2014, 02:12:26 PM »
I guess it is not static electricity caused the death of the hall sensors as I repeated that 3 times and every time everything was switched off. Turn on -> a dead.

Actually I've put for a test a 100K resistor before the connection to the arduino. Well that fixed both problems, however I don't know a) why the problems happened at all, at least the one with thousands of interrupts and b) why the resistor fixed both of them :)

So with a 100K resistor:
- when arduino is switched off, the controller is not messed up and is still working
- also interrupts started to work correctly and arduino counts correctly when a magnet passes trough the hall sensor.


Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #64 on: October 06, 2014, 01:57:40 AM »
Another problem discovered - 5-10 times per full rotation the arduino generates two instead of one interrupts (the time difference between them is in the range of 12-16 MICRO seconds!) as well instead only in case of RISING it does it in case of FALLING (while I haven't set any interrupt catch for FALLING).
The solution is to create interrupts on "CHANGE" and then to ignore all of them that happened in less that 100 microseconds after the last one (this method works for speeds less than 1300km/h).
Now FINALLY I have the correct values for speed and distance at the LCD screen!
:)

Offline Morgen 3Eman

  • Confirmed
  • PhD. Magic
  • ******
  • Posts: 620
Re: MP III + speedometer?
« Reply #65 on: October 06, 2014, 02:20:08 AM »
So, are you telling us that you are now using an edge to generate the interrupt?  And it works?  Or is this another problem?

Dennis

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #66 on: October 06, 2014, 09:26:44 AM »
Yes, using the signal from the MP3's hall sensor, routed trough the pedelec's signal cable which I don't used before, connected trough 100K resistor to the interrupt pin of the arduino works well finally. For some reason it generates double interrupts sometimes, but as explained I filter those at software level and as a result now I measure exactly 58 ticks per 360 degrees precisely.
The software displays speed and distance correctly. Now I am waiting to receive the stepper motors to use them instead of the LCD screen.

Offline Morgen 3Eman

  • Confirmed
  • PhD. Magic
  • ******
  • Posts: 620
Re: MP III + speedometer?
« Reply #67 on: October 06, 2014, 05:43:30 PM »
Hi MP3test

I'm an old electronic problem solver, and I'm trying to understand exactly what solved the problem.  So would you please state exactly, were you using a level interrupt to start, and the did the oscillation problem go away when you changed to an edge interrupt, like "Rising" or "Falling"?  Or were you using the same interrupt the whole time, and the oscillation went away when you inserted the resistor in the input circuit? Or did you have the pin you used as a input  configured as an output?  What scheme was it? Please explain it to me. 

I don't mean to be a pain in the neck about this, but I really want to learn from this episode so I can be helpful on the next problem.

TTFN,
Dennis

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #68 on: October 06, 2014, 07:25:02 PM »
Yes, I am not as well someone that just find a solution and leave it that way without understanding but in this case the problem is my electronics knowledge is close to 0 (I personally had a feeling that after a resistor the voltage should drop; when nothing worked I started just to experiment with a multimeter in hands; so I discovered that after the resistor the voltage was exactly the same 4.5V and tried what will happen if I put it before the arduino; I am feeling like experimentators 1000 yers ago :)
I am sure this is pretty simple to calculate anyway.

But the interesting question is where the oscilations come, why after the resistor Arduino sometimes had double interrupts with a delay of just 12-16 micro seconds; and for me - why 100K Ohms? I just tried with 300 K - it is still working. I guess at some point of increase it will start losing the signal so I'd like to know:
How to calculate the right resistor's value, so the signal is still strong for Arduino, while the current is the smaller, so it doesn't mess when going back into Arduino when it is switched off and panic the controller at the same time.

So the scheme was the same all the time:
- I've got the yellow wire of one of the hall sensors from the motor
- soldered it to an unused wire of the pedelec signal to get it out of motor
- in the beginning - just put it in the INT0 of arduino (this is a digital input that can be used to triger interrupts)
- then the only change I did is to add the resistor (the red one)
- all the time I was using the setting "RISING" for the interrupts which should mean that an interrupt should be generated only when the voltage changes from low level (I guess under 2.5V) to high level

Without the resistor the know problems were 3:
- on switched off Arduino, the voltage of the hall sensor dropped to 1.35V and so the MP3 was panicked
- many people told me that it can damage the Arduino as back current goes into it's scheme
- and the strange oscillations - when the current was 4.5V Arduino was generating for some reason 2500-5000 interrupts; even more strange - when the signal from hall sensor was 0V, Arduino generated 200-300,000 interrupts

With the resistor the 3 problems were fixed:
- on switched off Arduino, MP3 now works
- I guess as just a small portion of the current now goes into Arduino it can't be damaged
- oscillations disappeared like with a magic
BUT I discovered new 2 problems:
a) rarely interrupt has been generating not on RISING but when the voltages drops to 0 (i.e. FALLING)
b) rarely when the voltage goes from 0 to 4.5V Arduino generated 2 consecutive interrupts; I measured the time difference and it was 12-16 micro (not milli) seconds
I fixed these by changing the interrupt setting to "CHANGE", so my function is called on any change - that way I fixed problem a), and then I started to measure the time between interrupts and if an interrupt happens too fast (I set it < 1000 microsenods to be sure) I just ignore it.
As a result I am increasing the counter just once per any change of the state of the hall sensor's signal.

Now:
- why the Arduino was generating so much interrupts?
- why the resistor fixed that
- why anyway sometimes there were double interrupts
- why anyway sometimes an interrupt rised on signal drop while it was set to catch the rising signal
- is the 100K resistor OK, or I can/have to replace it with 300 or more K Ohms? And how to decide which is the best?

The connection are those that I have already posted:

Offline Morgen 3Eman

  • Confirmed
  • PhD. Magic
  • ******
  • Posts: 620
Re: MP III + speedometer?
« Reply #69 on: October 06, 2014, 08:18:27 PM »
Hi MP3test

Since the resistor cured the oscillation problem, my GUESS would be that the Arduino was drawing so much current from the MP3 circuitry that the MP3 power supply or the Hall sensor was going into a short circuit protection mode, where power is shut off for a period, then allowed back on to see  if the short circuit has cleared.  (Sometimes that scheme is called "over-current foldback"). And that is an educated guess, but still just a guess. 

The addition of the resistor limited the amount of current the Arduino could draw from the MP3 to a low enough level to get away from the over-current foldback regime or what ever was oscillating.  It reduced the max current draw from something probably over 20 milliAmps  (The max the Hall sensor can deal with)  to something about 50 microAmps.

Regarding the resistor sizing, the input current drawn by FETs is in the nanoAmp range, so you could probably use a MegOhm resistor and still have the circuit work.  But the smaller  R makes the circuit more noise resistant. 

TTFN,
Dennis

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #70 on: October 07, 2014, 02:00:56 AM »
I think I measured how much Arduino draws from the hall sensor and it was below 1mA (but I'm not 100% sure now I forgot the value). But I remember it was too low (I knew that MP3 has 50mA or something).

Do you have an explanation how 0V (measured with Arduino - analog input and multimeter) when connected to the digital input could generate RISING interrupts? :) For the 4.5V there may be an explanation, but for 0V it is kind of weird.

Just from the math standpoint my personal explanation is that the MP3's DC-DC converter does the conversion somehow by impulses. The 48V if divided 2500 times per second to small impulses may produce those 5V average measured with multimeter. If it divides 48V 200K times per second, it goes down like 0V when measured with multimeter, but in fact those are just tiny impulses of 48 Volts. Is it working that way, or my fantasy is more than needed? :)

Because the other question is why my hall sensors all died when I connected them to the "5V" wire coming from the MP3? That happened to 3 of them the same way. For me this is not a real 5V current but something else.

Offline Morgen 3Eman

  • Confirmed
  • PhD. Magic
  • ******
  • Posts: 620
Re: MP III + speedometer?
« Reply #71 on: October 07, 2014, 04:31:22 AM »
Hi MP3test

Switching power supplies typically run a 20-200 KHz, and if the current draw was enough to bring the output to zero, then you might see that frequency when the load was shorted enough to drain the filter capacitor to zero volts.  But I would expect there to be some diode drop voltage showing up somewhere, like your earlier reading of 1.3 V, which is what I would expect from two diodes in series.... But just flat 0 Volts?  Mighty peculiar in my experience, except for electro mechanical shorting. 

However, my MP3 has a linear 5 VDC regulator, not a switching supply.....So that doesn't make sense either.  Maybe your 12VDC supply is a switcher?  Maybe your MP3 is a later version and has a 5 V switcher?  I have no idea.

Give me access to your problem with an  oscilloscope, and I'll tell you what is causing the symptoms, but from where I stand right now, I don't have any good ideas.   

Regarding the rising interrupt question, I have to assume the Arduino saw a rising signal on the line from the unknown cause above.

My experience makes me think you inadvertantly did something wrong with the sensors, and you killed them.  (I have had trained technicians install circuit board backwards.  People do things wrong, me included. Did I tell you about the time I set fire to a semiconductor manufacturing  plasma deposition  machine I designed and built?)  (In a clean room!)

TTFN,
Dennis

Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #72 on: October 07, 2014, 05:44:55 PM »
As now I am proceeding with the voltmeter, to avoid the same problem that when arduino is off no (significant) power should be attached to its inputs, I did a voltage divider and added another 100K resistor at its end. However there is small voltage drop with it compared to the circuit without it. So I need help here - how the V2 is calculated in the following circuit:



And now I am feeling ever more stupid as yesterday I discovered that by adding a simple resistor it doesn't change the voltage (but lower the current entering the arduino) a text I am reading says just the opposite. Can you help me?



When measured with a multimeter, the voltage with or without the resistor was the same and as everyone agreed by adding that resistor I drop the current which goes into arduino.

While this text says "the current is the same in each resistor" (and so it should be the same with or without the resistor) and that the voltage is proportional to the resistor and so there should be a voltage drop after the resistor.

Seems the difference comes from the different standpoitns but this is not common sense at all for me, so I will be grateful if someone enlightens me!




Offline Morgen 3Eman

  • Confirmed
  • PhD. Magic
  • ******
  • Posts: 620
Re: MP III + speedometer?
« Reply #73 on: October 07, 2014, 07:01:07 PM »
Hi MP3test

First off, R3 is not needed, and is a bad idea to include it.  R1 by itself is enough to prevent loading the MP3 when the Arduino is powered off.   

Regarding the resistor value choice, I like to use round numbers, so I'm going to use 60VDC for the supply voltage, ok? I have no idea why you picked the 52V you used…..It is a good idea to have the max probable analog input voltage  to be less than the A/D rated input max of 5VDC.

At 60 Volts, 220KOhms will allow .273 mA current.  The voltage developed at the junction of the resistors will be 5.5 volts.  That is above the Arduino Vcc of 5Vdc, so that isn't a good choice.  If we change the 200K for a 300K, we than have 320K Ohms total, and the current drops the draw to about 190 MicroAmp       By why draw even 190 microAmps?  It just wastes power! How about something in the 10 microamp range?  That implies a resistor chain value about 5 MOhms.  The closest standard value is 4.7 MegOhms, so lets use that for R1.  For R2 lets guess that it needs to be about 400 KOhms, (which is not a standard value, but it is a round number) and do the math.  the total R will be 5.10 MegOhms, which gives us a current of about 12 microAmp,  and a junction voltage of 4.7 Vdc.  So that is a prettty close guess.  The standard value resistors close to 400 K are 390 K and 430 K if I remember correctly.  They would give a junction voltage of  4.59 Vdc, which is pretty good,  and  5.03 Vdc, which is too high.  So using the 4.7 Meg/390 K combination will give you low power loss, and resolution of about 50 milliVolts/step for the A/D. 

So with that combination we can read 0-60 volts to within a few milliVolts.  But if we are measuring a"48v"  LiPo battery we aren't very interested in anything outside the 60V max to 48Vmin. 

It turns out there is  device called a Zener Diode, which will drop a constant voltage when operated within limits. If we install a 48V Zener between V1 and R1, the voltage at the top of R1 will only be 12 Volts.  And now the A/D steps will be about 12 millivolts.  Probably more resolution that we really need, but is that bad? 

I have no idea if a 48V zener is available, but you can Google for close values, and make the calculations for yourself.

I hope that helps. 

TTFN,
Dennis



Offline MP3test

  • Confirmed
  • Magic Undergrad
  • ***
  • Posts: 54
Re: MP III + speedometer?
« Reply #74 on: October 07, 2014, 08:30:14 PM »
Thank you!
At the picture I've put example numbers just for the calculations, as I still have my question - suppose there are 3 resistors as shown, how can I calculate the V2? I know the math if only R1 and R2 are present, but with R3 - just don't know what to think. Following the example of adding a single resistor before the connector this should lead us that the voltage will be the same with R3 as without it but this is not the case. So what am I missing?

As for the reality, all the resistors are +/- some %. So I've got some and measured them with a good multimeter, so I have the exact values.

I used so far 98.7K and 8.11K which gives 4.32V when the battery is at 56.9V (measured at full charge) down to 3.64V (if the battery goes to 48V at full discharge, not sure if it goes so low). Arduino has a scale of 1024 per 5V, so I'll have about 140 different values for the 4.32-3.64V interval (the corresponding of 56.9-48V of the battery). I hope this will be sufficient to show the battery "capacity" as there is no linear relation between the capacity and voltage but we will see what will happen.

So using your advice I'll forget about the third resistor (but please tell me how to calculate V2 in case of R3, just for curiosity) and I will use just megaohm for R1 and corresponding for R2. Actually as in a bad knowledge situation like mine, I will set up 3-4 combinations of R1 and R2 at the same time to see if they will give equal results in practice, or we have some omited unknown variables that we ignore and not only the Ohm's law apply but some other's as well (like omitting the friction when calculating movement or something) :)

Regarding the Zener diode - is it working in a linear way? I mean that it always drops constant voltage or it depends on the V1? Adding more errors or non linearity in the circuit will make it more difficult to guess the battery's capacity.