Pages: 1 [2]   Go Down
Author Topic: Help reading analog pins  (Read 576 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
God Member
*****
Karma: 17
Posts: 522
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, if you are feeling ambitious, you could try to solve this problem in the analog domain, with something like this:

http://www.edn.com/design/analog/4347834/Circuit-converts-pulse-width-to-voltage

Then just analogRead() and Bob's your uncle. This approach would probably be non-trivial to actually implement, for the average Arduino hobbyist, but I did want to point out that it's available.
Logged

UK
Offline Offline
Tesla Member
***
Karma: 134
Posts: 7594
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The radio signals seem to be standard RC servo signals. Can you access the signal before it is divided into 4 separate streams.  That is how they would be sent from the originating transmitter. That would allow you to read all the pulses on a single pin and would allow you to write your own interrupt code to measure them if pulseIn() isn't suitable. I wrote some code to identify model railway DCC signals and it relied on using a specific pin that triggers interrupts so that it would not be possible to use that technique for multiple signals. I think it could be amended for your purpose.

Perhaps you could multiplex the 4 pulses with a few logic gates - maybe they "accidentally" retain the channel spacing that would have been in the transmitted multiplexed signal.

...R
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Is there a way to use pulseIn with another timer than the one used by the interrupts?
pulseIn() doesn't use a timer. It waits for the state to change or for millis() to have advance far enough. Since millis() doesn't advance when you have interrupts disabled, it's hard to believe that disabling interrupts allows pulseIn() to work. Not hard, actually. Impossible. Unless the thing that enables pulseIn() to return is that the signal actually changes.

Turning interrupts off disables servo pulses, so it's no surprise that the servo doesn't move.

So, why are you turning interrupts off?



Turning interrupts off and then on actually helped for the PulseIn function. My input was clear, with no oscillations.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your answers.
I wanted to clarify that using noInterrupts(), code, Interrupts() actually WORKS for my receiver signal, but messes up my PWM command to the servos.

I want to find a way to read my input without messing the other stuff up (maybe use another timer and do something similar to pulseIn() ?? ).

I'm looking for ideas online, but I haven't found anything useful yet... I refuse to believe that I'm the only one who's trying to make an RC device using Arduino.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I use the noInterrupt in my getValues() function, then I can read the values perfectly, but my servo won't work anymore.
Is there a way to use pulseIn with another timer than the one used by the interrupts?

You can use the external interrupt to replace the pulseIn() call. Set it to CHANGE mode and store the value of micros() on the first edge, then take the difference between the stored value and the current value of micros() to get the pulse length. This way you don't have to deactivate the interrupts and your servos still work.
Another way is to just deactivate the Timer0 interrupt but then you have to be careful in programming, because you must not use millis(), micros(), delay() and other functions being dependent on them.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought of external interrupts too, but I think that arduino has only 3(?) pins on which you can define external interrupts, and I cannot use those...
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought of external interrupts too, but I think that arduino has only 3(?) pins on which you can define external interrupts, and I cannot use those...

A standard UNO has 2 external interrupts.Why can't you use them? You still might have the chance to use pin change interrupts though.
Logged

Pages: 1 [2]   Go Up
Jump to: