Skip to content

Commit

Permalink
updating blinker02
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch67 committed Apr 9, 2016
1 parent 35aa250 commit 9f8c002
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
16 changes: 15 additions & 1 deletion ATSAMD21/blinker02/README
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ allow us to modify the OSC8M register.
By simply changing the prescaler we can adjust the speed of the clock.

This example will do three on/off cycles at 16 seconds per cycle, then
then from there the leds will change state every 1 second.
then 7 on/off cycles at 2 seconds per cycle. Then I have some
code that shows another way to use a timer that wraps around. By
changing the load value to all ones (this is a 24 bit timer) it counts
from 0xFFFFFF to 0x000000 and then "wraps around" to 0xFFFFFF which
means it counts forever. I know it is a down counter because the ARM
docs said that, you have to check some timers are up some are down
some you can configure to be up or down. So long as you dont wait
longer than a single wrap around (with some margin) you can simply
compare the difference between reading the timer one time and then
reading it later to see how much time has elapsed. The last loop
demonstrates this. And is the most generic as you often find a timer
can be setup to wrap around and you dont have to get into the details
of that specific timer to figure out how to check that it has finished
counting, how to re-arm it, etc. Any wraparound timer you can just
read it once then read it again and subtract (and mask).

Remember this is not a crystal oscillator, it is not that accurate.
The docs say that there is calibration data (meaning each individual
Expand Down
34 changes: 33 additions & 1 deletion ATSAMD21/blinker02/blinker02.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ int delay ( unsigned int n )
int notmain ( void )
{
unsigned int ra;
unsigned int rb;

if(1)
{
Expand Down Expand Up @@ -81,7 +82,9 @@ if(1)
ra&=~(3<<8);
PUT32(OSC8M,ra);

while(1)
if(1)
{
for(ra=0;ra<7;ra++)
{
PUT32(PORTAOUTSET,1<<17);
PUT32(PORTAOUTSET,1<<27);
Expand All @@ -92,6 +95,35 @@ if(1)
PUT32(PORTBOUTCLR,1<<3);
delay(8);
}
}

PUT32(STK_CSR,4);
PUT32(STK_RVR,0x00FFFFFF);
PUT32(STK_CVR,0x00000000);
PUT32(STK_CSR,5);

rb=GET32(STK_CVR);
while(1)
{
PUT32(PORTAOUTSET,1<<17);
PUT32(PORTAOUTSET,1<<27);
PUT32(PORTBOUTSET,1<<3);
while(1)
{
ra=GET32(STK_CVR);
if(((rb-ra)&STK_MASK)>=1234567) break;
}
rb=ra;
PUT32(PORTAOUTCLR,1<<17);
PUT32(PORTAOUTCLR,1<<27);
PUT32(PORTBOUTCLR,1<<3);
while(1)
{
ra=GET32(STK_CVR);
if(((rb-ra)&STK_MASK)>=1234567) break;
}
rb=ra;
}

return(0);
}

0 comments on commit 9f8c002

Please sign in to comment.