Skip to main content
grammar spell correct.
Source Link
Chetan Bhargava
  • 4.6k
  • 5
  • 28
  • 40

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.

Ok so right now, i have created 2 different PWMs using timer 1 and 2, that is used to control a linear motor. im using a hall effect sensor to detect changes in voltage as the linear motor moves left and right. This change in voltage i feed into a ADC pin in the atmega8 in order to convert it to digital. Then i basically use the USART functions of the atmega8 to display the voltage the hall effect sensor basically detects.

Im 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.......

currenntly what happens is that as soon as i do that the pwm stops working, its as if the program is stuck in the interrupt in an infinite loop.

HOWEVER if i remove the serial transmission function, the pwm starts working again...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 freuqency with BAUD of 9600.

However when i take off USARTWriteChar(read); (still keeping rad = ADCH ) from the ISR the pwm works meaning the ADC interrupt is not causing problems but USART is for some reasons.

I have created 2 different PWMs using timer 1 and 2 on ATmega8, that is used to control a linear motor. I'm using a hall effect sensor to detect changes in voltage as the linear motor moves left and right. This change in voltage I feed into a ADC pin in the ATmega8 in order to convert it to digital. Then I basically use the USART functions of the ATmega8 to display the voltage the hall effect sensor basically detects.

I'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.......

Currently what happens is that as soon as I do that the PWM stops working, its as if the program is stuck in the interrupt in an infinite loop.

However, if I remove the serial transmission function, the PWM starts working again 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 frequency with BAUD of 9600.

However when I take off USARTWriteChar(read); (still keeping rad = ADCH ) from the ISR the PWM works meaning the ADC interrupt is not causing problems but USART is for some reasons.

edited body
Source Link
subz
  • 623
  • 1
  • 9
  • 14

Ok so right now, i have created 2 different PWMs using timer 1 and 2, that is used to control a linear motor. im using a hall effect sensor to detect changes in voltage as the linear motor moves left and right. This change in voltage i feed into a ADC pin in the atmega8 in order to convert it to digital. Then i basically use the USART functions of the atmega8 to display the voltage the hall effect sensor basically detects.

Im 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.......

currenntly what happens is that as soon as i do that the pwm stops working, its as if the program is stuck in the interrupt in an infinite loop.

HOWEVER if i remove the serial transmission function, the pwm starts working again...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 freuqency with BAUD of 9600.

However when i take off USARTWriteChar(read); (still keeping rad = ADCH ) from the ISR the pwm works meaning the ADC interrupt is not causing problems but USART is for some reasons.

Ok so right now, i have created 2 different PWMs using timer 1 and 2, that is used to control a linear motor. im using a hall effect sensor to detect changes in voltage as the linear motor moves left and right. This change in voltage i feed into a ADC pin in the atmega8 in order to convert it to digital. Then i basically use the USART functions of the atmega8 to display the voltage the hall effect sensor basically detects.

Im 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.......

currenntly what happens is that as soon as i do that the pwm stops working, its as if the program is stuck in the interrupt in an infinite loop.

HOWEVER if i remove the serial transmission function, the pwm starts working again...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);    
 }

Ok so right now, i have created 2 different PWMs using timer 1 and 2, that is used to control a linear motor. im using a hall effect sensor to detect changes in voltage as the linear motor moves left and right. This change in voltage i feed into a ADC pin in the atmega8 in order to convert it to digital. Then i basically use the USART functions of the atmega8 to display the voltage the hall effect sensor basically detects.

Im 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.......

currenntly what happens is that as soon as i do that the pwm stops working, its as if the program is stuck in the interrupt in an infinite loop.

HOWEVER if i remove the serial transmission function, the pwm starts working again...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 freuqency with BAUD of 9600.

However when i take off USARTWriteChar(read); (still keeping rad = ADCH ) from the ISR the pwm works meaning the ADC interrupt is not causing problems but USART is for some reasons.

edited body
Source Link
subz
  • 623
  • 1
  • 9
  • 14

{ //TRANSMISSION FUNCTION

void USARTWriteChar(uint8_t data) { //Wait untill the transmitter is ready

while(!(UCSRA & (1<<UDRE))) { //Do nothing }

//TRANSMISSION FUNCTION

 void USARTWriteChar(uint8_t data) {            //Wait untill the transmitter is ready

    while(!(UCSRA & (1<<UDRE)))
      {
    //Do nothing
      }

     UDR=data;

}

//PWM while (1) { OCR1A = Push1; // Output compare register A Time 1
OCR1B = 0;

  }

//Main function containing PWM

  while (1)
   {
    OCR1A = Push1;                                  // Output compare register A Time 1  
    OCR1B = 0;
    _delay_ms(onF400);                                 // set on time A     


             
     
    OCR1A = 0;                                      
    OCR1B = 0; 
    _delay_ms(offF400);                                    // set dead time B

    
}

 //Interrupt function   

  ISR(ADC_vect) {

   read = ADCH;

   USARTWriteChar(read);    
 }

//Interrupt function

ISR(ADC_vect) {

read = ADCH;

USARTWriteChar(read); }

}

{ //TRANSMISSION FUNCTION

void USARTWriteChar(uint8_t data) { //Wait untill the transmitter is ready

while(!(UCSRA & (1<<UDRE))) { //Do nothing }

UDR=data;

}

//PWM while (1) { OCR1A = Push1; // Output compare register A Time 1
OCR1B = 0;

    _delay_ms(onF);                                 // set on time A    
             
     
    OCR1A = 0;                                      
    OCR1B = 0; 
    _delay_ms(offF);                                    // set dead time B

    
}

//Interrupt function

ISR(ADC_vect) {

read = ADCH;

USARTWriteChar(read); }

}

//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);    
 }
edited body
Source Link
subz
  • 623
  • 1
  • 9
  • 14
Loading
Source Link
subz
  • 623
  • 1
  • 9
  • 14
Loading