1
\$\begingroup\$

I am trying to interface the GPS module with my ARM board. GPS sends RS232 signals from its single pin (say pin Z).

I want to use the watchdog timer for receiving and parsing the serial stream. Any idea of using watchdog in this context?

\$\endgroup\$
  • 7
    \$\begingroup\$ Why do you want to use the watch dog instead of a normal timer/interrupt? \$\endgroup\$ – jsolarski Mar 7 '11 at 8:10
  • 4
    \$\begingroup\$ Why can't you use a UART? \$\endgroup\$ – Leon Heller Mar 7 '11 at 11:12
  • \$\begingroup\$ i don't have the UART port free in my board. There is just one UART port which is already used. i don't have any problem using normal timer interrupt either \$\endgroup\$ – user3276 Mar 7 '11 at 16:55
  • \$\begingroup\$ i have a 4800 bps 8N1 signal coming from the GPS device. So for my purpose i need to use some way to interrupt in (1/4800 bps) = .2 ms i need to check if the device support such a small value for normal interrupts. \$\endgroup\$ – user3276 Mar 7 '11 at 17:02
  • 1
    \$\begingroup\$ You need to sample more often than 1/4800 seconds. How are you synchronizing to the start bit so that you can sample in the center of the data bits? \$\endgroup\$ – markrages Mar 7 '11 at 19:22
6
\$\begingroup\$

You probably want to use an ordinary timer interrupt and sample at perhaps 8 times the baud rate though four times might possibly work (in hardware implementations 16x is common, but I've personally done it at 8x).

Most processors of modern clock speed should be able to fire an interrupt that fast, at least if your code in the ISR is efficient and you don't have much else interrupt-driven running.

You will probably want to run a state machine, advancing one state on each interrupt. Basically you look for the start bit transition and then read each data bit an appropriate number of oversampled cycles later. There are lots of implementations of this for FPGAs in verilog or VHDL floating around the net, translating back to assembly or C should not be difficult.

However, as you can likely reprogram your timers and interrupt modes quickly, there is another option for optimization: You could start out by having an edge sensitive interrupt on the input pin. When that fires, you then program a timer interrupt to generate delays of precisely a bit period (not oversampled), and simply read out the state on each interrupt. When the word is concluded, re-arm the edge interrupt.

But there is a catch with this optimized method: because you are only "paying attention" at the important times, you have to work harder to make sure that the initial transition is a start bit, and that you aren't catching some data word in mid-flight when your code starts up. Probably you want to do this by using your edge interrupt to make sure that the input has been in a quiescent state long enough (long enough since the last interrupt) - if it hasn't, discard what your get and wait for a clean character.

Some googling on "UART state machine" or the like would be informative. There's always the chance you will find reference code for your particular processor, particularly if it has no hardware UART or only one.

\$\endgroup\$
  • 1
    \$\begingroup\$ Oversampling at 3x baud is better than 4x. At N*baud rate, with N odd, the allowable margin is 1/2N. If N is even, the allowable margin is 1/N. \$\endgroup\$ – supercat Mar 9 '11 at 15:41
4
\$\begingroup\$

You cannot use the watchdog timer, as that resets the processor on almost (all?) processors.

You could insert code in your reset routine, but this would be backwards as the data memory of the chip is usually cleared on reset.

\$\endgroup\$
  • 1
    \$\begingroup\$ That was my thought on how the watchdog worked on most chips. \$\endgroup\$ – jsolarski Mar 7 '11 at 10:56
  • \$\begingroup\$ At least on the AVR reset on watchdog and interrupt on watchdog can be toggles using a control register. So you can use the watchdog timer purely for interrupts. The benefit is that the watchdog can have interrupt periods of up to 8s, whereas the regular timers are limited to much less. \$\endgroup\$ – drxzcl Mar 7 '11 at 14:06
  • \$\begingroup\$ okie thanks for the reply. i have a 4800 bps 8N1 signal coming from the GPS device. i need to store the information in the buffer of the board. So for my purpose i need to use some way to interrupt in (1/4800 bps) = .2 ms i need to check if the device support such a small value \$\endgroup\$ – user3276 Mar 7 '11 at 17:01
  • 1
    \$\begingroup\$ Most processors don't clear data memory on reset. Though startup code might wipe out some portion of it, or potentially leave a DRAM controller misprogrammed long enough to make memory contents unreliable. Nonetheless, resetting the processor would be a roundabout way to solve the problem. \$\endgroup\$ – Chris Stratton Mar 8 '11 at 18:06
2
\$\begingroup\$

Another possibly applicable method is to use an external circuit to select one of the two input sources and feed the signal to the UART.

For this to be appropriate you need to know when you're expecting data so that you can switch to the appropriate device.

Another option is to add an external UART and receive data from that. It's kinda hard to be more specific without knowing more of the platform available.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy