Xmega 128A1 xplain Count Up Timer

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

Hi Guys,

I know this probably sound stupid, but can someone teach me how to set up a count up timer? I want it to count say from 0 to 10 secs, in 1 sec interval.

I kind of feel that its relatively easy and only needs a few lines of code, but I am noob at AVR programming. Sorry, please help!

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

uint8_t count = 0;

while (count < 11) {
    delay_ms(1000);
    count++;
    // to display on LEDs:
    PORTE.OUT = ~count;
}

Gamu The Killer Narwhal
Portland, OR, US
_________________
Atmel Studio 6.2
Windows 8.1 Pro
Xplained boards mostly

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

Hi GTKNarwhal,

Thank you for your prompt reply!

With slight modification to the code above, just want some help to verify this code of mine, is there any obvious mistakes? like is long double used correctly in this case?

#include delay.h

long double count = 0, dist;

while(count<10) 
{

	delay_ns(100);
	count=count+0.0000001;
	
	if(sinewave)
	{ dist=count*340.29;
	  printf dist;
		break;
	}
	  
}

will the LCD print out the value of dist if I were to use the A3Bu xplained board?

Thank you.