Sign in

username:

password:



Not a member?

Search basicx



Search tips

Subscribe to basicx



basicx by Keywords

Accelerometer | ADC | ADXL | Adxl20 | AVR | BasicStamp | BX-35 | BX28 | BX35 | COM3 | Compiler | Downloader | EEPROM | Electromagnet | GetADC | GP2D1 | GPS | I2C | IDE | Keypad | LCD | LCD+ | MIDI | Motors | Multitasking | Netmedia | Networking | PCB | PID | PlaySound | PWM | Relays | RTC | Servo | ShiftOut | SitePlayer | SPI | Stack | Timer | USB


Ads

Discussion Groups

See Also

DSPFPGAElectronics

Advertise Here

Discussion forum for the BasicX family of microcontroller chips.

Faster! - Tom Becker - Jan 30 17:09:35 2007

Ever looked at your output on a scope and wished that the occasional
one-tick glitch wasn't there? You might be able to get rid of it.

If you do not need the RTC, you can turn Timer0 off and still
multitask, despite the loss of the 512Hz system tick. In fact, BX-24
code will run faster and more regularly if Timer0 is disabled.

Your programming must, if the system tick is disabled, be cooperative
multitasking code. You need to take care in loops, since you are in
control of time; you can't, for example, wait for a pin to rise like
this:
Do Until (GetPin(5) <> 0)
Loop

Instead, you must offer a task switch by calling Sleep(0):
Do Until (GetPin(5) <> 0)
Call Sleep(0)
Loop

Many system function calls can also cause task switching like Sleep(0)
can; a loop that fills an output queue, for instance, won't need a Sleep
(0) since the queue functions do so, implicitly.

The benefit of this is speed. I'm working on a sampling device for
example, that could do only 150Hz sampling because the BX-24 OS seemed
to take an entire tick on occasion and that, in turn, would cause the
loss of a sample. I turned off Timer0 and cranked it up to 240Hz
wihout missing a beat. I lost the RTC (the values from Timer, GetTime,
GetTimeStamp and register.RTCTick, never change), and found that the
IDE's ATN is undiscovered (requiring a manual Reset for each download)
but, otherwise, the program runs fine without Timer0.

I suggest adding a Sleep(0.5) at the start of your code, just in case,
to give the IDE a chance to gain control of the machine before you turn
Timer0 off and lose that facility.

To turn off Timer0 you can:
register.TCCR0 = 0
or
register.timsk = register.timsk and &hFE
Tom


(You need to be a member of basicx -- send a blank email to basicx-subscribe@yahoogroups.com )