Analog Signal to UART

Discussion in 'Embedded Systems and Microcontrollers' started by lolspock, Mar 22, 2009.

  1. lolspock

    Thread Starter New Member

    Mar 22, 2009
    2
    0
    I have an analog signal at my device that I want to be able to read at a computer through its serial connection. I am planning to use MATLAB to read in the value of the analog signal, because I know it has a toolbox that can interface with COM ports in the computer.

    I am planning on putting the analog signal into an A/D converter that is sampling about 30kHz. I have looked at some that can do serial output (but I do not think UART) and parallel output.

    From here I am lost. Should I use a PIC to generate the UART signal?

    Thanks for any help.
     
    Last edited: Mar 22, 2009
  2. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Several PIC's come with onboard A-to-D (typical 10-bit resolution) and USART capability. So you could avoid most of the external A-to-D part altogether. Some input signal conditioning is probably a reasonable expectation.

    I've used the PIC18F258 series for a purpose very similar to yours and it works fine. These take up to 5 analog input channels.

    If you need higher resolution you can apply oversampling to the on-board A-to-D data in your code or use an external serial A-to-D (8-pin DIL) chip (12-bits quite simple) on the SPI line.

    If you can obtain a development board (& support software) with some flexibilty in configuration that would make the process easier.

    Have fun.:)
     
  3. lolspock

    Thread Starter New Member

    Mar 22, 2009
    2
    0
    Some schematics I have seen have a Max232 chip. It looks like it boosts the amplitudes of the signal to the right values to send over a serial cable. Is this what that chip does and do I need one on the output of the PIC?
     
  4. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    That's right - you need to match the interface signal levels between your PIC [just logic levels] and the connected PC [RS232 levels & control lines]. The MAX232 is designed to make the interfacing easier to implement.
     
  5. t_n_k

    AAC Fanatic!

    Mar 6, 2009
    5,448
    782
    Also as I said previously, you can buy development boards - depends on your budget of course! Plus you have the development software / programming interface hardware costs.

    Several development boards can be purchased with an RS232 hardware interface option built in.

    I'm sure you will find plenty of guidance re options from others at AAC or on the web in general.

    Of course there are equally suitable chip options other than the MAX232 for serial interfacing .... I don't want to imply or promote a preference for a particular manufacturer.
     
  6. leftyretro

    Active Member

    Nov 25, 2008
    394
    2
    I think the 30khz sampling rate will be the main challenge you will have to deal with. This will require a fast uP with maybe on board storage and a high baud rate to move the data on out.

    Lefty
     
  7. zigbee09

    New Member

    Mar 30, 2009
    2
    0
    Does anyone know of a website that has code examples for doing this? I just need to know how to take in an analog signal at the ADC and output it via the UART. If anyone has some advice on how to program that, I would greatly appreciate it.
     
  8. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I posted in another thread just today how to sample ADC and display the value on 3 7 segment LED displays.

    In the same thread, I posted code for receiving serial, I believe the title is "PORTA.0" something.

    Also "Just get a value and send it over UART" was something in the realm of impossible/thousand dollar projects not too long ago. So if it seems difficult, it is slightly more involved than blinking an LED, but we'll help all we can. :)
     
  9. zigbee09

    New Member

    Mar 30, 2009
    2
    0
    I am trying to use BASIC to program this. So far I have:

    INCLUDE "bs1defs.bas"
    DEFINE OSC 20 'run at 20 Mhz
    DEFINE ADC_BITS 8 ' Set number of bits in result
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    TRISA = 255 ' Set PORTA to all input
    TRISB = 0 ' Set PORTB to all output
    ADCON1 = 2 ' PORTA is analog
    ADCIN 0, B0 ' Read channel 0 to B0
    Serout 0,T2400,[B0]

    When I try to compile, I get an error saying something about undefined symbol 'trisb'

    Does anyone know what this error is talking about? If I comment out the line with trisb in it the error goes away, but I'm fairly sure that I need that line.

    Also, can anyone tell me if I am at least on the right track here? I'm completely new at PIC programming. Thanks!
     
Loading...