Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Ads

Discussion Groups

See Also

DSP

Discussion Groups | Comp.Arch.Embedded | AVR-GCC ADC example source

There are 8 messages in this thread.

You are currently looking at messages 0 to 8.

AVR-GCC ADC example source - Andrew Tweddle - 2006-04-20 23:07:00

I have been looking on the web for AVR-GCC example sources on using the 
ADC converter in the ATmega32 or a related processor, to my 
disappointment, I have only found the Atmel AVR465: Energy meter 
example, are there any other examples both simple and complex on setting 
up and using this peripheral?

Andrew



Re: AVR-GCC ADC example source - Craig Ruff - 2006-04-20 23:29:00

In article <44484c48$1...@news.chariot.net.au>,
Andrew Tweddle  <s...@alphalink.com.au> wrote:
>I have been looking on the web for AVR-GCC example sources on using the 
>ADC converter in the ATmega32 or a related processor, to my 
>disappointment, I have only found the Atmel AVR465: Energy meter 
>example, are there any other examples both simple and complex on setting 
>up and using this peripheral?

This is from a simple application I use to decode the WWVB time codes.
It is using the GCC AVR tool chain.  It samples the amplified and filtered
analog signal at 256 Hz to decode the time signal.

This is part of the initialization code:

//
// Setup A/D, use AVCC for ref, ADC0 as input, left adjust value
// Prescale CPU clock by 64 => 2,400 samp/sec max
//
ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(ADLAR);
ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);

Later on:

void
GetTime(void)
{
        uint8_t         prev;
        uint8_t         s0;
        uint8_t         s1;
        uint8_t         s2;
        uint8_t         s3;
        uint8_t         sf;
        uint16_t        t16;
        EdgeState       estate;

        Write_P(PSTR("GetTime started\n"));
        //
        // Prime the pump
        //
        ADCSRA |= _BV(ADEN);
        ADCSRA |= _BV(ADSC);
        while (bit_is_set(ADCSRA, ADSC))
                /**/;

        s0 = s1 = s2 = ADCH;
        prev = now = TCNT0;
        estate = EdgeDetect(EPrep, 0);
        while (estate != Done) {
                //
                // Wait for the next tick
                //
                while (prev == now) {
                        now = TCNT0;
                }

                prev = now;
                //
                // Get the next sample
                //
                ADCSRA |= _BV(ADSC);
                while (bit_is_set(ADCSRA, ADSC))
                        /**/;

                s3 = ADCH;

                //
                // Filter the noise
                //
                t16 = s1 + 2 * s2 + s3;
                sf = t16 / 4;
                estate = EdgeDetect(estate, sf - s0);
                s0 = s1;
                s1 = s2;
                s2 = sf;
        }

        ADCSRA &= ~_BV(ADEN);
}

Re: AVR-GCC ADC example source - Andrew Tweddle - 2006-04-21 00:49:00

Craig Ruff wrote:


> void
> GetTime(void)
> {
>         uint8_t         prev;
>         uint8_t         s0;
>         uint8_t         s1;
>         uint8_t         s2;
>         uint8_t         s3;
>         uint8_t         sf;
>         uint16_t        t16;
>         EdgeState       estate;
> 
Thankyou for the prompt reply!
Next question. What is edgestate, a simple boolean value?

Andrew

Re: AVR-GCC ADC example source - Craig Ruff - 2006-04-21 08:24:00

In article <44486405$1...@news.chariot.net.au>,
Andrew Tweddle  <s...@alphalink.com.au> wrote:
>Thankyou for the prompt reply!
>Next question. What is edgestate, a simple boolean value?

typedef enum { EPrep, Rise, Fall, Done } EdgeState;

Forgot to mention that this is running on a ATmega128.  The WWVB time
code is PWM encoded in the power level of the 60 KHz carrier signal.
The codes represent a position marker 'P', a binary 0 and binary 1.
The EdgeDetect routine is looking for the transitions of the filtered
signal.  The way the analog circuitry is wired, the default state
of the A/D values is to be at a higher number, so I sync up by looking
for the higher numbers, then watch for a falling edge whcih represents
the start of the second and the code.  The amount of time the signal is
at a lower number represents which code is being sent:

	0.2s = 0
	0.5s = 1
	0.8s = P

A more detailed description of WWVB can be found at:

	http://tf.nist.gov/stations/wwvb.htm

Re: AVR-GCC ADC example source - BobG - 2006-04-21 11:58:00

Andrew: many examples and helpful friendly members at avrfreaks.net


Re: AVR-GCC ADC example source - Andrew Tweddle - 2006-04-22 03:50:00

BobG wrote:

> Andrew: many examples and helpful friendly members at avrfreaks.net
> 
The people might well be friendly but the interface drives me crazy!.It 
would have to be one of the worst web interfaces with all that redrawing 
every time you look at a new thread or message. Just a BG Bandwidth hog 
and absolutely no advantage to their advertising or thier user base, 
beats me? But thanks anyway, so endith the gripe.

Andrew

Re: AVR-GCC ADC example source - BobG - 2006-04-22 09:13:00

What the regulars do is hit the 'maximize' button on the menu, and the
ads go away.


Re: AVR-GCC ADC example source - Andrew Tweddle - 2006-04-23 22:23:00

BobG wrote:

> What the regulars do is hit the 'maximize' button on the menu, and the
> ads go away.
> 
Thankyou!