hey guys,
I really need someone's help. I'm trying for some days now but it still doesn't work. I'm trying to read to signals (on pin 19 and 20) with the ATtiny26. On both pins I want to read the voltage (0...5 V), so that I get a value between 0 and 255. ..and so on... at last the value should be sent to the hardware-PWM-output of the controller.
It's quite strage.. I tried this with one signal and it worked without any problem. But if I try to read a second signal it doesn't work anymore. >__<
Please, I really need help!! I have to finish the work till tomorrow! >__<
Here's my code. It might explain it better. Sorry for my poor English. ><
Code:
#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;
// 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;
};
}
Thank you very much for your help!!! ^__^ |