ESP8266 fnwait

Discussion of issues related to writing ZBasic applications for targets other than ZX devices, i.e. generic targets.
Post Reply
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

ESP8266 fnwait

Post by FFMan »

Don

a short while ago you wrote the code below for me as i wanted short-period wait function that would allow other tasks to run.

Question - what should the divide by value be for an esp8266 ? I

Code: Select all

'100,000 microseconds in a second
Sub fnWait(byVal ulWaitMicroseconds as unsignedlong)

	dim mt0 as Microtime_t
#if Option.TargetDevice="328l"			
	dim ulWaitCycles as unsignedlong = CUlng(CSng(ulWaitMicroSeconds) / 8.68)
#else
	dim ulWaitCycles as unsignedlong = CUlng(CSng(ulWaitMicroSeconds) / 4.34)
#endif

	dim ulDelta 	as unsignedlong
	
	Call GetMicroTime(mt0)
	ulDelta = GetElapsedMicroTime(mt0)
	
	while ulDelta<ulWaitCycles
		Yield
		ulDelta = GetElapsedMicroTime&#40;mt0&#41;
	wend
	
end sub
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: ESP8266 fnwait

Post by dkinzer »

FFMan wrote:what should the divide by value be for an esp8266 ?
The RTC timer runs at 5MHz so it has a 200ns period. That means that the divisor should be 0.2, I think.

http://www.zbasic.net/doc/ZBasicESP8266.php?page=14
- Don Kinzer
Post Reply