interrupts not working

Go To Last Post
15 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi guys,

I am using the following code in cvavr, my code is not working. My adc read code is working if i don't use interrupt. So there is issue with my interrupt call, i tried to make it manual call :

void main(void)
{
     DDRB=0xFF;
     DDRC=0xFF;
     PORTC=0x00;
     PORTB=0x00; 
     
     LCD_Init(); 
     delay_ms(100);
     adc_init();
     #asm("sei")
     while (1)
      { 
      delay_ms(1000); 
      PORTB.2= ~PORTB.2;
      }
}
interrupt [ADC_INT] void adc_isr(void)
{ 
    ADCSRA  |= (1<<ADSC);
    read_adc();
}

 

This topic has a solution.
Last Edited: Fri. May 6, 2016 - 11:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What happened to adc_init() ? Or read_adc() come to that?

 

Also which AVR is this?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What happened to adc_init() ? Or read_adc() come to that?

These are my custom functions, and there is no error in them. Because without interrupt format they are working fine.

Also which AVR is this?

This is code vision avr. I am coding for ATMEGA 16. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These are my custom functions, and there is no error in them. Because without interrupt format they are working fine.

 Still, show a small complete test program that demonstrates the symptoms.

 

If your read_adc() does a "polled" conversion, then your program posted, with ADIE enabled, will have cascading interrupts.

 

Show the complete program.  Tell what "not working" means.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Because without interrupt format they are working fine.Because without interrupt format they are working fine.

How can you rule out that with interrupts enabled they are working differently than with interrupts disabled.

 

If you want help, then don't try to outsmart the resident members here. They (uhmm, "we") almost always have a good reason for asking to see the whole picture. If not for something else, then for ruling out any possible problems in unseen code.

 

Or just let people here know if you want help or just an argument.

 

If it is true rthat your adc_read() works just fine without interrupts being enabled then I claim that it should look different with interrupts enabled. Thus, it makes no sense saying that the non-interrupt version is working fine in a non-interrupt situation.

 

So, please just show a minimal but complete program that builds and runs and demonstrates the problem. Scaling things down to the minimal program is what you have to pay for getting advice here for free.

 

Your call.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void read_adc()
{
     
      while (ADCSRA &  (1<<ADSC));
      theLowADC = ADCL;
      theTenBitResults = (ADCH<<8)|theLowADC;
      adc_value =  theTenBitResults;
      
}   
void adc_init()
{     ADCSRA &= 0x00;
      ADCSRA |= (1<<ADEN|1<<ADIE|1<<ADPS2|1<<ADPS1|1<<ADPS0);
      ADMUX &= 0x00;
      ADMUX |= (1<<REFS0);

This code contains adc_init() and read_adc()

Kindly see it too.

Last Edited: Thu. Sep 25, 2014 - 01:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tell what "not working" means.

 If your read_adc() does a "polled" conversion, then your program posted, with ADIE enabled, will have cascading interrupts.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Tell what "not working" means.

even when i change the value at ADC pins. No interrupt is called and no adc_isr runs. i.e. no interrupt is called. 

 If your read_adc() does a "polled" conversion, then your program posted, with ADIE enabled, will have cascading interrupts.

this is code with ADIE ( ADC interrupt enable) flag programmed. Since i am using adc as interrupts. In my polling case, (1<<ADIE) was not present in above code. 

Last Edited: Thu. Sep 25, 2014 - 01:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, hamzatheman.

 

We don't want the code in snippets, pierce by piece when we ask for it. We want the whole program in one piece in one post. It's nothing personal, but we've seen so meny cases here where the code is presented piecemeal and then it turns out that we didn't get to see what was actually on the computer at the person owning the problem.

 

So, again. Post a minimal but complete program that builds and runs and demonstrates the problem.

 

this is code with ADIE ( ADC interrupt enable) flag programmed. Sinice i am using adc as interrupts. In my polling case, (1<<ADIE) was not present in above code. 

This is exactly what I am having trouble with! Vague and hard to interpret statements about what is and what was.  Such things are worthless when trying to help. "No in that code I had that thing set to whatever, but now I have something else and you don't need to know it all but it is not working so why?". Just a waste of time. Keep it up and people will walk away and you will be alone.

 

Give hard facts. The hardest facts you can present is actual code. A complete program, but not more than what is necessary. It is your job to come up with this. This is the investment you have to do to get the profits from us.

 

Your call. Still.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Thu. Sep 25, 2014 - 01:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <mega16.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>  
#include "mylcd.c"
#include "adc.c"
#include <stdint.h>
void adc_init();
void display_adc();
uint8_t theLowADC;
uint16_t theTenBitResults;
uint16_t adc_value;
unsigned char k[7];
unsigned int flag; 
char positionx[4];
char positiony[4];
#define led PORTB.2;
unsigned int j;
void main(void)
{
     DDRB=0xFF;
     DDRC=0xFF;
     PORTC=0x00;
     PORTB=0x00; 
     
     LCD_Init(); 
     delay_ms(100);
     adc_init();
     #asm("sei")
     while (1)
      { 
      delay_ms(1000); 
      PORTB.2= ~PORTB.2;
      }
}
interrupt [ADC_INT] void adc_isr(void)
{ 
    ADCSRA  |= (1<<ADSC);
    read_adc();
}
void read_adc()
{
     ADCSRA  |= (1<<ADSC);
      while (ADCSRA &  (1<<ADSC));
      theLowADC = ADCL;
      theTenBitResults = (ADCH<<8)|theLowADC;
      adc_value =  theTenBitResults;
       itoa(theTenBitResults,k);
      showstringat(k,11,1);
      delay_ms(100); 
      showstringat("    ",11,1);
      delay_ms(100);
}
void adc_init()
{     ADCSRA &= 0x00;
      ADCSRA |= (1<<ADEN|1<<ADIE|1<<ADPS2|1<<ADPS1|1<<ADPS0);
      ADMUX &= 0x00;
      ADMUX |= (1<<REFS0);
}

well here the code goes. i hope that this is ok now.

Last Edited: Thu. Sep 25, 2014 - 02:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wrong in so many levels...

if you don't start conversion, there is no conversion completition interrupt ...

also interrupt should be as short as possible (no waits and so..)

+ if you want to see value of adc_value in main, it must be declared as volatile

...

Computers don't make errors - What they do they do on purpose.

Last Edited: Thu. Sep 25, 2014 - 02:45 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

You never start an initial conversion so you never get to the ADC.

 

When you use the interrupt you don't call the read_adc() function inside the ISR, it replaces read_adc. In the ISR you should just read the current ADC value, then start the next conversion.

     theTenBitResults = (ADCH<<8)|theLowADC;
      adc_value =  theTenBitResults;

Why do you use two variables for this?

ADCSRA &= 0x00;
ADCSRA |= (1<<ADEN|1<<ADIE|1<<ADPS2|1<<ADPS1|1<<ADPS0);
ADMUX &= 0x00;
ADMUX |= (1<<REFS0);

Why the |='s and &='s? Surely this can be done in two lines with ='s.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i changed adc_value to volatile, still the interrupt is not working.sad

BTW thanks. 

 

Last Edited: Thu. Sep 25, 2014 - 04:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it me or are you repeatedly ignoring the excellent advice you keep getting here? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

well problem is solved thanks koschi........

ADC interupts works.....  Another person "Ian" helped me in sorting it out . Thanks Ian very very much.