Hi hardcore,
The key is to use the PIC's built in peripheral modules. Most "modern" PICs have at least one CCP module (Capture Compare PWM module) that, in conjunction with one of the PIC's hardware timers can be set up to generate any frequency and duty cycle you want (within limits depending on oscillator speed etc). The PBP command HWPM uses the CCP module to do this but it has it's limitations which you can get around by writing the registers manually.
Let's see, a 16F628 running at 20Mhz....(this is untested but try it out, read the datasheet section on CPP module and TMR2 in this case)
Code:
DEFINE OSC 20
TRISB.3 = 0 'Set CCP pin to output.
CCP1CON = %00001100 'CCP module in PWM mode
PR2 = 9 '~500kHz
TMR2L = 20 '~50% duty cycle at 500kHz
T2CON = %00000100 'TMR2 ON, prescaler 1:1
Main:
'Do whatever.
Goto Main
Another very common peripheral is the USART (16F628 has one) which can be used to send data out over a serial line, it is also hardware so you set it up for the baudrate you want (or let PBP so it for you) and then just write a character to it and IT will send it out - no need to bit-bang it out with SEROUT. The PBP command HSEROUT for example uses the hardware USART to send data.
There are several other hardware periphelals bulit in to most PICs that you have to master and take advantage of. Think of it, it's only the last couple of years that the CPU's used in modern PC's have gone "multi-core" yet they've been able to get them doing quite a bit of work "in parallel" by using IT'S hardware peripherals and clever time-slicing and other multitasking tricks.
If you REALLY think you need "multi-core" then take a look at Parallax Propeller chip, it has 8 CPUs with shared RAM and some pretty cool things can be done with it. (Never tried one myself though).
/Henrik.
Bookmarks