Basir Atan wrote: > I am currently generating the fixed frequency > using tmr0 interrupt and generating the 2nd frequency using > software loops. However, using the loop, my resolution is > not constant. Any tips? The loop is being interrupted by TMR0 and so isn't going to operate as you expected. The only solution I can think of is to use TMR0 at a higher frequency and calculate when to change the two outputs according to where TMR0 is up to. You have this 4 or 10MHz oscillator that you are dividing to get either 400Hz or 425.0Hz to 375.0Hz. Otherwise use another PIC. A 12C509 slaved off the first? ;-) ;-) I've stuck the numbers into xspread (a Linux spreadsheet) and calculated the error you'd get from using the method I suggest. In all cases the error is less than 1%. How much error you can cope with is your problem. I would imagine that the TMR0 interrupt would increment a second counter, and that your code would neatly stop waiting for an interrupt and start polling TMR0 itself for the final few cycles. I'm a perfectionist. Column explanations; Clock, frequency in hertz of the PIC oscillator you are using, Desired, the frequency you want on an output pin, Count, how many clock cycles you will need to count, Rounded, the count rounded to nearest whole number (*), Actual, the frequency if we use that rounded count, Error, the ratio between the desired and actual frequencies. (*) this should be rounded to nearest TMR0 cycle, which is clock divided by four, but I'll leave that as an exercise for the reader. I present two tables of numbers, the first for 10Mhz, the second for 4Mhz. Clock 10000000 Desired Count Rounded Actual Error 400.000 25000.00 25000.00 400.000 1.000000 375.000 26666.67 26667.00 374.995 1.000012 375.200 26652.45 26652.00 375.206 0.999983 375.400 26638.25 26638.00 375.404 0.999991 375.600 26624.07 26624.00 375.601 0.999997 375.800 26609.90 26610.00 375.799 1.000004 376.000 26595.74 26596.00 375.996 1.000010 424.000 23584.91 23585.00 423.998 1.000004 424.200 23573.79 23574.00 424.196 1.000009 424.400 23562.68 23563.00 424.394 1.000014 424.600 23551.58 23552.00 424.592 1.000018 424.800 23540.49 23540.00 424.809 0.999979 425.000 23529.41 23529.00 425.007 0.999982 Clock 4000000 Desired Count Rounded Actual Error 400.000 10000.00 10000.00 400.000 1.000000 375.000 10666.67 10667.00 374.988 1.000031 375.200 10660.98 10661.00 375.199 1.000002 375.400 10655.30 10655.00 375.411 0.999972 375.600 10649.63 10650.00 375.587 1.000035 375.800 10643.96 10644.00 375.799 1.000004 376.000 10638.30 10638.00 376.011 0.999972 424.000 9433.96 9434.00 423.998 1.000004 424.200 9429.51 9430.00 424.178 1.000051 424.400 9425.07 9425.00 424.403 0.999992 424.600 9420.63 9421.00 424.583 1.000039 424.800 9416.20 9416.00 424.809 0.999979 425.000 9411.76 9412.00 424.989 1.000025 -- James Cameron (cameron@stl.dec.com) OpenVMS, Linux, Firewalls, Software Engineering, CGI, HTTP, X, C, FORTH, COBOL, BASIC, DCL, csh, bash, ksh, sh, Electronics, Microcontrollers, Disability Engineering, Netrek, Bicycles, Pedant, Farming, Home Control, Remote Area Power, Greek Scholar, Tenor Vocalist, Church Sound, Husband. "Specialisation is for insects." -- Robert Heinlein.