Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Urgent ADC mega16 help!

Urgent ADC mega16 help!

2004-07-31 by gary_hobson2003

HI!
My problem with adc is that it does not take samples as I want.I give
a 40HZ sine to differential input of it but the more I increse the
frequency the more periods I get and the resoloution does not
change.In the following result of adc data samples I have 32 samples 
for a 40HZ sine(which sould be more than 80 samples).when I want to
increase the frequency of sampling I increase TCOUNT0  to oveflow
sooner and get more data,but for TCOUNT0=254 it just gives me
zero!!!.Here is the program  and data results.Please guide me.
Thank you...


#include <mega16.h>
#include <stdio.h>
#include <delay.h>
#define nos 7 // Define number of samples
unsigned int current_word; // Global variable for the current ADC output
int i=0,j=0,k=0;
long int sum=0;
int temp[80];
int adc_data[80];
int templ,temph;
// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{ 

templ=ADCL; // Get 10 bit data from the ADC register 
/*if((ADCH&0x02)!=0)  
{
#asm
push r16
in r16,0x05
neg r16
out 0x05,r16
pop r16 
#endasm 
}*/ 
temph=ADCH;   
}
// When Timer 0 overflows, conduct this routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{               

#asm
cbi 0x06,7
sbi 0x06,7
#endasm
TCNT0=252;
 putchar(templ);                                         
// putchar(0);
 putchar(temph); 

}
void main(void)
{
DDRA=0x00; // All PORTA bits input
PORTC=0x00; // Set all eight bits of PORTC Low
DDRC=0xFF; // Set all eight bits of PORTC to Output
TCCR0=0x05; // Clock value: 7.2 kHz (7.3728MHZ / 1024) 
TCNT0=0; // Timer/counter 0 initialization
TIMSK=0x01; // Timer interrupt initialization
ADMUX=0xD0;  // Only look at ADC pin 0, ref. 2.56 INTERNAL           
                                                                     
                                                                     
                                                                     
                                                                     
                                                                     
                                                    
ADCSRA=0xEF; // ADC on, prescaler division factor = 128 
[1/(7.3728e6/128)]=138.8e-6___//
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: Off
// USART Transmitter: On
// USART Mode: Asynchronous
// USART Baud rate: 115200
UCSRA=0x00;
UCSRB=0x08;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x03; 
//SFIOR|=0x80;

#asm("sei") // Global enable interrupts
while (1);
}




  -86.8000  -87.2000  -86.4000  -84.2000   86.4000  306.4000  379.8000

  Columns 267 through 273 

  255.8000   16.2000  -86.6000  -87.6000  -88.0000  -73.2000  128.2000

  Columns 274 through 280 

  331.0000  371.8000  221.8000  -17.2000  -86.6000  -87.8000  -87.8000

  Columns 281 through 287 

  -57.8000  167.8000  349.8000  358.4000  185.0000  -46.4000  -87.4000

  Columns 288 through 294 

  -86.0000  -86.8000  -32.4000  205.0000  366.6000  340.2000  147.4000

  Columns 295 through 301 

  -65.0000  -86.4000  -87.6000  -87.0000   -1.2000  239.8000  377.0000

  Columns 302 through 308 

  317.4000  107.2000  -79.2000  -87.8000  -85.8000  -85.6000   35.2000

  Columns 309 through 315 

  271.0000  381.0000  291.0000   65.2000  -87.2000  -86.8000  -86.8000

  Columns 316 through 322 

  -85.0000   77.8000  300.2000  379.2000  261.4000   22.6000  -88.0000

  Columns 323 through 329 

  -89.4000  -86.2000  -75.4000  120.2000  326.0000  374.6000  229.4000

  Columns 330 through 336 

  -11.4000  -88.4000  -88.6000  -86.6000  -59.2000  159.0000  346.8000

  Columns 337 through 343 

  361.8000  193.6000  -40.2000  -87.2000  -88.0000  -89.4000  -38.8000

  Columns 344 through 350 

  197.4000  363.8000  344.4000  155.6000  -61.4000  -85.8000  -87.0000

  Columns 351 through 357 

  -88.6000   -9.2000  233.0000  375.4000  322.6000  115.2000  -76.8000

  Columns 358 through 360 

  -85.8000  -85.2000  -83.6000






and another result:






  -87.6000  -86.8000  -87.4000   14.6000  254.4000  378.4000  306.6000

  Columns 197 through 203 

   89.2000  -82.8000  -87.6000  -87.4000  -86.6000   54.2000  285.4000

  Columns 204 through 210 

  381.6000  279.8000   47.4000  -84.8000  -87.2000  -85.8000  -82.0000

  Columns 211 through 217 

   95.8000  312.0000  379.2000  249.0000    9.2000  -88.0000  -86.6000

  Columns 218 through 224 

  -86.6000  -68.8000  137.2000  336.0000  370.0000  214.4000  -23.4000

  Columns 225 through 231 

  -86.0000  -85.6000  -85.0000  -52.8000  175.4000  353.6000  354.0000

  Columns 232 through 238 

  177.0000  -51.6000  -87.2000  -87.2000  -87.0000  -26.4000  212.6000

  Columns 239 through 245 

  369.6000  335.6000  138.6000  -69.8000  -88.0000  -87.0000  -85.2000

  Columns 246 through 252 

    5.6000  247.0000  378.4000  313.0000   98.6000  -82.8000  -90.2000

  Columns 253 through 259 

  -87.2000  -85.6000   45.2000  279.4000  382.2000  287.0000   56.4000

  Columns 260 through 266

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.