While loop not breaking

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

The overall function of the program is to drive an LED strip using voltage across the ADC pins, maybe this is the correct way to go about this or maybe it isn't, I am a total newbie. I'm using Atmel Studio 7, I have attached  the main.c below because the file is quite large, it compiles fine on my machine. So far I have managed to turn the ADC on and set the relevant registers to read from a pin. While completing the ADC the program is supposed to wait for the ADC interrupt to trigger and set a flag letting the program know to continue. When the program continues it will read the data from the ADC and run the relevant functions that use that data, repeating as needed.

 

The problem I'm facing is that during debugging the wait loop never breaks even when the condition for break is met. I've pasted a screenshot showing the exact values at the problem source, it SHOULD be breaking.

 

I faced an issue previously where an unset pointer was causing the program to step over certain checks and managed to fix it, so it's possible that is causing an issue again?

 

Any help on this would be great.

 

Attachment(s): 

This topic has a solution.
Last Edited: Tue. Feb 20, 2018 - 03:59 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

ADCFlag needs to be volatile

 

 

How to properly post source code: https://www.avrfreaks.net/comment...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot, was really scratching my head on this one.

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

Note that this is a standard 'C' thing  - not specific to AVR.

 

EDIT

 

typo

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Feb 20, 2018 - 02:40 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

While it may not be AVR specific you may want to read this...

 

https://www.avrfreaks.net/forum/t...

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

Thanks I will take a look, haven't done much reading into C and I've been coddled by higher level languages .