energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
794 stars 672 forks source link

Change millis() / micros() to use Systick on Tiva based boards #400

Closed Luis-R-A closed 9 years ago

Luis-R-A commented 10 years ago

I want to sugest a change in the milis()/micros() fuctions

I'm realy don't exacly know how to read code in direct access coding but i belive millis() uses micros() to count wich uses TIMER5 right?

Well i think this is a big waste of a timer wich can be used for PWM, pulse measuring or sometigh else since Tiva has a dedicated timer for that, the system tick.

i use this to simulate millis() void SysTickbegin(){ SysTickPeriodSet(F_CPU/1000);// for miliseconds, F_CPU/1000000 for microseconds SysTickIntRegister(SycTickInt); SysTickIntEnable();

} void SycTickInt(){ milis++; //micros++ if period set to F_CPU/1000000 }

it's also possible to use the Tiva RTC for this since it's possible to get the 1/32768 ticks but it would have a error less than 0.3 micro seconds each microsecond. This would be make possible even to use the milis() as a RTC counter and would probably be a better option.

rei-vilo commented 10 years ago

Just a comment on the way; the RTC module isn't implemented in any LaunchPad as the battery line is hard-linked to main supply. I hope coming LaunchPads will feature a trace to cut so we could use a cell-coin battery to power the RTC module.

Luis-R-A commented 10 years ago

yea but it still works, unfortunaly just not in a separate power source, unfortunaly, this is such a big drawback in the hibernation module

Luis-R-A commented 10 years ago

Systick is used for delayMicroseconds, wich is used by delay, but there is no reason not to use it also for milis, i actualy use it for both

just use sometigh like this (i am just working with milis but it can be adapted to use micros)

void delay(int time){ int temp=milis(); while(milis()-temp < time);

}

robertinant commented 9 years ago

This was fixed with commit: 9f7447641f9bc2e04ba6781618a05a8c9b30c681