Thank you very much Eric.
What I did is Following (Surprisingly, its not working in desired way.)
Can anyone suggest me?
#include "printf.h"
uint16_t coarseValues;
uint16_t fineValues;
uint16_t COARSECOMPARE = 0x7FFF;
uint16_t fineOffset = 0x000E;
uint16_t coarseOffset = 0x0021;
uint16_t coarseWasCalled = 0;
module ClockCount
{
provides
{
interface TaskCount as TC;
}
uses interface HplAtm128Compare<uint16_t>;
}
implementation
{
async event void HplAtm128Compare.fired()
{
TCCR3B = 0x00;
atomic coarseWasCalled++;
atomic coarseValues++;
TCNT3 = 0x0000; //Counter3 clear
TCCR3B = 0x09;
}
async command void TC.startCounting()
{
atomic coarseValues = 0;
atomic fineValues = 0;
//Actual Timer/Counter
TCNT3 = 0x0000;
//Set counter clear on match (Couter Control Registers)
TCCR3A = 0x80;
TCCR3B = 0x09;
//Interupt mask set (Extended Timer Interrupt Mask Register)
ETIMSK = 0x10;
//Compare values (Output Compare Register)
OCR3A = COARSECOMPARE;
}
void calculateFine()
{
uint16_t callOffset = (coarseWasCalled * coarseOffset)/COARSECOMPARE;
//Was Commented............
atomic coarseValues = coarseValues + callOffset;
if (coarseWasCalled)
{
atomic fineValues = TCNT3 - coarseOffset;
atomic coarseWasCalled = 0;
}
else
{
//there is a 13 overhead on running the counter
atomic fineValues = TCNT3 - fineOffset;
}
}
async command void TC.stopCounting()
{
TCCR3B = 0x00;
calculateFine();
}
command unsigned int TC.getCoarseValue() {atomic return coarseValues;}
command unsigned int TC.getFineValue() {atomic return fineValues; }
command void TC.setCoarseCompare(uint16_t newCompare)
{
COARSECOMPARE = newCompare;
OCR3A = newCompare;
}
command void TC.setFineOffset(uint16_t off)
{
atomic fineOffset = off;
}
command void TC.setCoarseOffset(uint16_t off)
{
atomic coarseOffset = off;
}
command void TC.sendValuesToScreen()
{
printf("Fine Value is %u:\n", fineValues);
printf("Coarse Value is %u:\n", coarseValues);
printfflush();
}
}
Thank you..........................
Regards,
Sobit
Graduate Researcher
Texas State University
On Mon, Mar 14, 2011 at 5:30 PM, Eric Decker <[email protected]> wrote:
>
> I assume you mean computation cost in terms of time.
>
> I haven't messed with the atmel processors in years and currently am
> working with the msp430 processors
> but the concepts are equivilent.
>
> There should be a h/w timer running on the atm128 that should be ticking at
> 1us. you need to find that
> timer register and figure out how to snapshot it.
>
> Then you take a snapshot at the start of the code you are measuring and
> then another when the computation
> completes. You need to be aware of the width of the timer and be careful
> of overflows which cause problems for
> determining the final result.
>
> eric
>
>
> On Mon, Mar 14, 2011 at 3:14 PM, Sobit Thapa <[email protected]> wrote:
>
>> Hi,
>>
>> I need a help regarding computation cost of a function which I want to
>> read in
>> Micro Second...............I need a sample code for Atm128 processor. Can
>> anybody please help me...........
>>
>> Its urgent and I appreciate your help.
>>
>> Regards,
>> Sobit
>> Graduate Researcher
>> Texas State University
>>
>> _______________________________________________
>> Tinyos-help mailing list
>> [email protected]
>> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>>
>
>
>
> --
> Eric B. Decker
> Senior (over 50 :-) Researcher
>
>
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help