It's also more easy to ask someone to write your code for you than to write it yourself. You're not asking for help. You're asking someone to do it for you.Helo Sagor,
Is okay, advice and write is more easy than practice knowledge.
Youtube is more better than forum.
Define CONFIG = 0x3f0a '16f628a 'Example of 18Khz interrupt to produce 9Khz output 'actual Output is 9009Hz due To rounding errors/accuracy with 8Mhz 'actual output is 8992Hz due to rounding errors at 20Mhz 'Use 8Mhz crystal Define CLOCK_FREQUENCY = 8.0 '8 Mhz 'Use 20 Mhz crystal 'Define CLOCK_FREQUENCY = 20.0 'Example using timer0 to set 55.5us interrupt 'for 8Mhz crystal OPTION_REG = 0x88 TMR0 = 145 INTCON = 0xa0 'enable interrupts and timer0 interrupt 'for 20Mhz crystal: 'OPTION_REG = 0x80 'TMR0 = 117 'INTCON = 0xa0 'enable interrupts and timer0 interrupt Enable 'Enable interrupts loop: 'main code here Goto loop End 'Interrupt routine with 8Mhz takes about 9us to complete without "Save System" 'Takes about 12.5us with Save System 'With 20Mhz crystal, total time will be 5uS with Save System On Interrupt Save System If INTCON.T0IF = 1 Then INTCON.T0IF = 0 'For 8Mhz crystal TMR0 = 145 'For 20Mhz crystal, reset to 20Mhz count: 'TMR0 = 117 'Enter your interrupt code here Toggle PORTB.0 Endif Resume
I would not change the 145 for TMR0 to 161 in real life. The simulator has timing issues, and the 145 should produce the proper 9.009 kHz frequency. If you want to get closer to 9.000 kHz, you would have to find a crystal frequency that gives a closer result. That would be trial and error, pure guessing what crystal to use.Helo,
Sagor : Thank you so much for the sample code, I tried it on simulation for 8Mhz external crystal I get 9,009 Khz or 9009 Hz, which I encrease the TMRO to 161 from 145.
Mike : I will tried as well as your advice, anyway thank you to for you.
I am really new in the Oshonsoft, I bought that compiler PIC16IDE and PIC18 Basic Compiler.
Please let you explain do with the PWM..., Thank you.PR2 = 62
T2CON.TMR2ON = 1
CCP1CON.2 = 1
T2CON.2 = 1
PWMduty 2, 0
Does that make any difference?, and in any case 8MHz is a bit 'in the middle' of XT and HS anyway - and personally I've never found it makes any difference at all, and I've certainly forgotten to change the setting sometimes when changing crystalsAre you sure you are running off the external 8Mhz crystal, in HS mode (not XT)?