Hi !
I have another issue !
Cannot get the ADC to work properly, the LED will only come on at 5V on the potentiometer !
#define F_CPU 16000000UL
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
int cylinder = 5;
uint16_t injection_time = 0;
uint16_t injection_gap = 0;
void delay(int t);
void cycle(void);
void sendFuel(int injector);
void sendSpark(int coil);
void getTPSValue(void);
int main(void)
{
DDRC |= (1 << PORTC0) | (1 << PORTC1) | (1 << PORTC2) | (1 << PORTC3) | (1 << PORTC4) | (1 << PORTC5);
MCUCR |= (1 << ISC01) | (1 << ISC00) | (1 << ISC11) | (1 << ISC10);
GICR |= (1 << INT0) | (1 << INT1);
ADCSRA |= (1 << ADPS0) | (1 << ADPS1) | (1 << ADPS2) | (1 << ADEN);
ADMUX |= (1 << REFS0) | (1 << ADLAR);
sei();
while(1)
{
getTPSValue();
if(injection_time < 512)
{
PORTC |= (1 << PORTC0);
}
if(injection_time > 512)
{
PORTC &= ~(1 << PORTC0);
}
}
}
void delay(int t)
{
while (t != 0)
{
_delay_ms(1);
t = t - 1;
}
}
ISR(INT0_vect) // CKP
{
cylinder++;
cycle();
}
ISR(INT1_vect) // CMP
{
cylinder = 0;
}
void cycle()
{
if(cylinder == 1)
{
sendFuel(PORTC0);
sendSpark(PORTC4);
}
if(cylinder == 2)
{
sendFuel(PORTC2);
sendSpark(PORTC5);
}
if(cylinder == 3)
{
sendFuel(PORTC3);
sendSpark(PORTC4);
}
if(cylinder == 4)
{
sendFuel(PORTC1);
sendSpark(PORTC5);
}
}
void sendFuel(int injector)
{
PORTC |= (1 << injector);
delay(35);
PORTC &= ~(1 << injector);
delay(35);
}
void sendSpark(int coil)
{
PORTC |= (1 << coil);
delay(10);
PORTC &= ~(1 << coil);
}
void getTPSValue()
{
ADCSRA |= (1 << ADSC);
while(!(ADCSRA & (1 << ADIF)));
ADCSRA |= (1 << ADIF);
injection_time = ADC;
_delay_ms(1);
}
Thank you so much for your help !
EDIT: Did some tests and it seems like the register ADCL is totally empty, whatever the input voltage on ADC0 is !