
Originally Posted by
HenrikOlsson
Hi,
OK, I don't know from where I got that you had 72 steps in the lookup table. Now I know it's 90. If can live with fewer steps you'll be able to increase the output frequency.
I'm pretty sure you're simply running out of time. I made some quick tests here but in order to do so I had to change your code a little bit (don't have 4431 handy to test on). So I'm not sure exactly how much we can depend on these.
I'm using a 18F4520 @20Mhz.
The interrupt routine itself runs in about 70us, the overhead introduced by the interrupt system (DT-ints) is from previous tests I've done about 29us (again at 20Mhz) at interrupt entry and I would guess about the same on exit. This means each interrupt takes a total of ~130us.
1/0.000130 = 7700Hz
I've verified this by specifying InterruptFrequency of 7700Hz and it works, I get 7700 Hz with nice, steady pulses. If I specify 8500Hz I can see on the scope that the trace is starting to get jittery indicating that it's starting to overrun it self, missing pulses so think I'm pretty close to the absolute max at 7500-8000Hz.
Now, in theory, since you're running at 40MHz you should be able to get twice that, ~15kHz but apparently you're not. Can you set a pin high at the beginning of the interrupt service routine and set it low just before @INT_RETURN, then measure how long that output is high. That will tell you the execution time of the actual handler (where I got 70us).
Are you sure that the PIC is running at 40Mhz? Simply specifying DEFINE OSC40 doesn't make it run at 40MHZ, you need to enable the PLL thru the CONFIG bits as well.
/Henrik.
With this :
Code:
' PWM calculation and update interrupt (Timer 1)
pwmint:
T1CON.0 = 0 ' Stop TMR1
TMRCopy.HighByte = TMR1H ' Copy value of TMR1 registers
TMRCopy.LowByte = TMR1L
TMRCopy = TMRCopy + TimerReloadValue ' Add reload value (compensates for overhead)
TMR1H = TMRCOPY.HighByte ' And back to TMR1
TMR1L = TMRCopy.LowByte
T1CON.0 = 1 ' Restart Timer
TOGGLE PORTD.7
@INT_RETURN
And a interrupt freq of 10800Hz, I get an output square wave of 720Hz on the oscilloscope.
Here is my config bits in MPLAB :

Note I'm using the HS oscillator with PLL enabled. My crystal (40MHz) is connected between OSC1 and OSC2 pins, with 2*47pF ceramic capacitors. On the oscilloscope, it's okay, I can see the oscillation.
Bookmarks