Ok so right now, iI have created 2 different PWMs using timer 1 and 2 on ATmega8, that is used to control a linear motor. imI'm using a hall effect sensor to detect changes in voltage as the linear motor moves left and right. This change in voltage iI feed into a ADC pin in the atmega8ATmega8 in order to convert it to digital. Then iI basically use the USART functions of the atmega8ATmega8 to display the voltage the hall effect sensor basically detects.
ImI'm running the ADC in free running mode with interrupts to continuously detect a hall effect value.
The problem im having at the moment is that as soon as the interrupt is called to read the adc value i have a function in the interrupt that involves transmitting the adc value to the screen.......
currenntlyCurrently what happens is that as soon as iI do that the pwmPWM stops working, its as if the program is stuck in the interrupt in an infinite loop.
HOWEVERHowever, if iI remove the serial transmission function, the pwmPWM starts working again...which which confuses me??
//TRANSMISSION FUNCTION
void USARTWriteChar(uint8_t data) { //Wait untill the transmitter is ready
while(!(UCSRA & (1<<UDRE)))
{
//Do nothing
}
UDR=data;
}
//Main function containing PWM
while (1)
{
OCR1A = Push1; // Output compare register A Time 1
OCR1B = 0;
_delay_ms(400); // set on time A
OCR1A = 0;
OCR1B = 0;
_delay_ms(400); // set dead time B
}
//Interrupt function
ISR(ADC_vect) {
read = ADCH;
USARTWriteChar(read);
}
I am running the ATmega8 at 8Mhz clock freuqencyfrequency with BAUD of 9600.
However when iI take off USARTWriteChar(read); (still keeping rad = ADCH ) from the ISR the pwmPWM works meaning the ADC interrupt is not causing problems but USART is for some reasons.