Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB

Ads

Discussion Groups

Discussion Groups | BasicX | Re: Reading multiple PWM sources?

Discussion forum for the BasicX family of microcontroller chips.

Reading multiple PWM sources? - Dan - Nov 18 16:40:50 2006

Thanks in advance for your advice... I'm totally stumped.

I would like to read two PWM sources with the BX and output a combined
signal, somewhat like making my own servo mixer. The end result will
be a downward-looking stabilized camera mount (already working) that
an onboard computer can send an "offset angle." The stabilization
offers a level-reference that allows the offset angle to point, for
example, a very steady 40deg forward and 30deg left. Welcome to my
GPS tracking camera mount!

I have two different PWM generators (one: stabilization by the
autopilot; two: the "offset" PWM signal from a SSC), so I can't
garuntee the frame alignment. I'm okay with some latency, so my idea
was to read a pulse on PWM1, read a pulse on PWM2, do my own mixing,
and output to the single servo.

My problem is that trying to read two PWM sources keeps reverting to
reading from only one source. When I connect the hardware for the
second PWM input, the first PWM input (even though it was working
before) suddenly switches to the same reading as the second PWM input.
It is almost like the command to read the first PWM input is being
overtaken by the shear fact the hardware sees pulses on the second PWM
input pin. Each works individually.

My best guess is that pulsein uses timer1 and maybe I need to force
the second PWM read onto timer2 somehow? I'm out of ideas and don't
know how to do this one. I have been reading around and searching
embeddedrealated for a couple days with no answers popping out.

My code seems simple enough ... what am I missing?

' ----------------------------------------------------------- '
Option Explicit

Public Sub Main()
Dim PulseWidthOne As Integer
Dim PulseWidthTwo As Integer

Delay(2.0)

Do
Debug.Print ""

' Wait for a high pulse on pin 16
PulseWidthOne = PulseIn(16, 1)
Debug.Print "One: "; cstr(PulseWidthOne)

' Wait for a high pulse on pin 17
PulseWidthTwo = PulseIn(17, 1)
Debug.Print "Two: "; cstr(PulseWidthTwo)

Delay (0.3)
Loop

End Sub
' ----------------------------------------------------------- '

Thanks again for any suggestions!
Dan



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )


Re: Reading multiple PWM sources? - mr_tentacle_too - Nov 18 22:27:30 2006

Just for completeness' sake, try calling the float version, which is
a procedure call rather than a function, and see if you get the same
results.
--- In b...@yahoogroups.com, "Dan" wrote:
>
> Thanks in advance for your advice... I'm totally stumped.
>
> I would like to read two PWM sources with the BX and output a
combined
> signal, somewhat like making my own servo mixer. The end result
will
> be a downward-looking stabilized camera mount (already working) that
> an onboard computer can send an "offset angle." The stabilization
> offers a level-reference that allows the offset angle to point, for
> example, a very steady 40deg forward and 30deg left. Welcome to my
> GPS tracking camera mount!
>
> I have two different PWM generators (one: stabilization by the
> autopilot; two: the "offset" PWM signal from a SSC), so I can't
> garuntee the frame alignment. I'm okay with some latency, so my
idea
> was to read a pulse on PWM1, read a pulse on PWM2, do my own mixing,
> and output to the single servo.
>
> My problem is that trying to read two PWM sources keeps reverting to
> reading from only one source. When I connect the hardware for the
> second PWM input, the first PWM input (even though it was working
> before) suddenly switches to the same reading as the second PWM
input.
> It is almost like the command to read the first PWM input is being
> overtaken by the shear fact the hardware sees pulses on the second
PWM
> input pin. Each works individually.
>
> My best guess is that pulsein uses timer1 and maybe I need to force
> the second PWM read onto timer2 somehow? I'm out of ideas and don't
> know how to do this one. I have been reading around and searching
> embeddedrealated for a couple days with no answers popping out.
>
> My code seems simple enough ... what am I missing?
>
> ' ----------------------------------------------------------- '
> Option Explicit
>
> Public Sub Main()
> Dim PulseWidthOne As Integer
> Dim PulseWidthTwo As Integer
>
> Delay(2.0)
>
> Do
> Debug.Print ""
>
> ' Wait for a high pulse on pin 16
> PulseWidthOne = PulseIn(16, 1)
> Debug.Print "One: "; cstr(PulseWidthOne)
>
> ' Wait for a high pulse on pin 17
> PulseWidthTwo = PulseIn(17, 1)
> Debug.Print "Two: "; cstr(PulseWidthTwo)
>
> Delay (0.3)
> Loop
>
> End Sub
> ' ----------------------------------------------------------- '
>
> Thanks again for any suggestions!
> Dan
>



(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )