I was wondering if someone can help me. Thank you.
Regards, Sobit B. Thapa Graduate Research Assistant Department of Computer Science Texas State University, San Marcos ________________________________________ From: [email protected] [[email protected]] On Behalf Of Thapa, Sobit [[email protected]] Sent: Tuesday, March 15, 2011 8:02 PM To: Michael Schippling Cc: [email protected]; [email protected] Subject: Re: [Tinyos-help] Question regarding computation time calculation for a task in MicroSeconds in Atmega128 Hi, Thank you very much for your valuable help. My results are varying so much as they are increasing continuously for same job when I distributed them among sensors. By the way, I did following to disable interrupts. ETIMSK = 0x10; It should work. Am I right? Regards, Sobit B. Thapa Graduate Research Assistant Department of Computer Science Texas State University, San Marcos ________________________________________ From: Michael Schippling [[email protected]] Sent: Tuesday, March 15, 2011 5:53 PM To: Thapa, Sobit Cc: [email protected]; [email protected] Subject: Re: [Tinyos-help] Question regarding computation time calculation for a task in MicroSeconds in Atmega128 How much do the results vary? There are other interrupts and such that happen during processing, so even a very regular "foreground" process might slip'n'slide a bit. At a cursory review level I'd think your code is probably OK, although I believe there is a counter wrap-around interrupt you could use for your coarse counter so you don't have to fool with the compare thing. I have some counter3 compare code here: http://www.etantdonnes.com/Motes/AVR128timers.zip if you want something to compare and contrast. MS Thapa, Sobit wrote: > I am using Timer3 as code posted below. I call startCounting() before a task > executes and I call stopCounting after task executes. > > But, I am getting variable result. Is there any mistake in my code or > somebody can provide code performing similar job. > > And, it is Atmega128 specific. > > #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(); > } > } > > > Sobit B. Thapa > Graduate Research Assistant > Department of Computer Science > Texas State University, San Marcos > _______________________________________________ > 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 _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
