PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Problem mit ADC und Codevision?!



ThiloG
07.05.2006, 11:38
Hallihallo,

Ich versuche seit einigen Tagen mit einem ATtiny26 zwei Signale (an pin 19 u. 20) zu verarbeiten. Irgendwie will das aber nicht richtig hinhauen...
An Pin 19 sowie an Pin 20 möchte ich die Spannung auslesen (0...5 V) und als Wert 0...255 erhalten, "verarbeiten" und an den PWM-Ausgang senden.
Ich hab mal mit einem Eingang rumprobiert, was problemlos geklappt hat. Sobald ich aber ein zweites Signal "empfangen" will, funktioniert es nicht mehr. >__<
Kann mir da vielleicht jemand weiterhelfen? bitte?

Vielleicht wird es etwas klarer, wenn man dazu meinen Code anschaut:


#include <tiny26.h>
#include <delay.h>

#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 1
unsigned char adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
unsigned char value_1;
unsigned char value_2;
#define ADC_VREF_TYPE 0x20
// ADC interrupt service routine
// with auto input scanning
interrupt [ADC_INT] void adc_isr(void)
{
register static unsigned char input_index=0;
// Read the 8 most significant bits
// of the AD conversion result
adc_data[input_index]=ADCH;
// Select next ADC input
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT|ADC_VREF_TYPE)+input_index;
// Start the AD conversion
ADCSR|=0x40;
}

unsigned char temp;
int temp1;

// Declare your global variables here

void main(void)
{
// Declare your local variables here

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=In Func1=Out Func0=In
// State7=T State6=T State5=T State4=T State3=0 State2=T State1=0 State0=T
PORTB=0x00;
DDRB=0x0A;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
TCCR0=0x00;
TCNT0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 500,000 kHz
// Mode: PWMA & B top=OCR1C
// OC1A output: Inverted, /OC1A disconnected
// OC1B output: Inverted, /OC1B disconnected
PLLCSR=0x00;
TCCR1A=0xF3;
TCCR1B=0x04;
TCNT1=0x00;
OCR1A=0xFF;
OCR1B=0xFF;
OCR1C=0xFF;

// External Interrupt(s) initialization
// INT0: Off
// Interrupt on any change on pins PA3, PA6, PA7 and PB4-7: Off
// Interrupt on any change on pins PB0-3: Off
GIMSK=0x00;
MCUCR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Universal Serial Interface initialization
// Mode: Disabled
// Clock source: Register & Counter=no clk.
// USI Counter Overflow Interrupt: Off
USICR=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
ACSR=0x80;

// ADC initialization
// ADC Clock frequency: 125,000 kHz
// ADC Voltage Reference: AREF
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=FIRST_ADC_INPUT|ADC_VREF_TYPE;
ADCSR=0xCD;

// Global enable interrupts
#asm("sei")

while (1)
{
value_1=adc_data[0];
value_2=adc_data[1];
if (value_1 == 0) value_1=1;
if (value_2 == 0) value_2=1;
temp=value_1*(1-(value_2/255));
OCR1B=temp;
};
}

Vielen Dank im Voraus!! ^__^