Riiiight! I forgot that the PIC is "running" at 1Mhz, not 4.
After reading over the datasheet a few more times, I think I've wrapped my head around the timers.
This code now seems to work (with the inclusion of a enable and disable), and should be outputting the right ratios (With the full output coming off of Clkout, and the rest coming out of B.7).
Code:
@ device pic16F648A, intrc_osc_clkout, mclr_off, protect_off, lvp_off, wdt_off
DEFINE OSC 4
TRISB = 0 ' Outputs on
CMCON = 7 ' Turn all comparators to fully digital (needed??)
OPTION_REG = %10000011 '$84 assign prescaler to TMR0, set prescale to 1:16
TMR0 = 2 'add 2 to timer if you're anal about it starting exactly on the 1st cycle
INTCON = %10100000 '$A0 enable TMRO interrupt
on interrupt goto clkreset
start:
goto start
clkreset:
disable
PORTB.7=1
PORTB.7=0
TMR0 = 2 'correct timer for missed cycles?
INTCON = %00100000 '$20 Reset interrupt set T0IE, clear T0IF
enable
resume
I don't have my scope handy (left it at work), so I can't measure the output, so I'm trying to figure out what frequency they're actually firing at. I know someone who's gotten this to work on the PIC I'm using (16F648A) with the internal clock, so I know this isn't a hopeless case...maybe there's something wrong with my math somewhere...math was always my weak point.
Thanks again for your ongoing patience and help!
Bookmarks