Hi,
1) What's the width of the pulses? Not the time between them but the width?
2) What's the value stamped on your x-tal?
3) The timing calculations that I provided are based on the fact that your chip is SUPPOSED to run at 40MHz, if it's not running at 40MHz then the timing will be wrong and the interrupt frequency will wrong as well.
4) Please don't quote the complete message you're responding to. It clutters the thread and it gets hard read because everything is quoted all the time - that's my personal view.
The pulses are very very thin :
The width of a pulse is 4,4µs.
Of course the crystal is stamped at 40MHz, I've difficulties with the setup of this timer, but I hope I'm not an idiot
The circuit :
![]()
Well, then that is likely the problem - or one of them... If you look at page 355 in the datasheet you'll see that the maximum x-tal frequency WITHOUT PLL is 25 MHz and with using the PLL it's 10MHz (resulting in 40Mhz). You're trying to use 40Mhz which is out of specs in both cases.Of course the crystal is stamped at 40MHz
The fact that your pulses are 4.4us wide while mine are 3us means that your chip is running way SLOWER than mine while in fact it "should" be running twice as fast.
Get the oscillator sorted and verify that the PIC is running at the speed you think. One way to do that is a simple program like:If you DON't get a 500Hz signal with 1ms wide pulses the chip isn't running at the correct and/or DEFINE'd oscillator speed.Code:DEFINE OSC 20 'Don't forget to DEFINE the correct OSC speed. TRISB.0 = 0 Main: PortB.0 = 1 Pause 1 PortB.0 = 0 Pause 1 Goto Main.
Okay, sincelery I'm quite new with the PICs, so I doesn't know this "problem" (in reality is not a problem).
I'll try to find a slower crystal tomorrow.
Okay, so I've unsoldered an 8MHz xtal (not an 10MHz unfortunately) on a old board, and I connected this one to the PIC.
I've enabled the PLL, so my PIC clocks at 8*4=32MHz.
On the oscilloscope, I get now a 2µs pulse, it's a little better.![]()
Now it seems to run properly - finally.
In order to make the calculations of the preload value match your new (32MHz) oscillator speed you need to change the Dummy2 value from 10000 to 8000.
Then keep the same test code in the interrupt service routine and try with InterruptFrequency = 10800, check the scope, there should now be pulses at 10800 or likely a little bit slower.
The reason it's not 10800 exactly is, again, due to time that the timer is actually stopped while reloading it. To tune it simply tweak the +1 in the following line:Try +12 or something and see what happens.Code:TimerReload = 65535 - TimerReload + 1
Then try adding code to your interrupt, not all at once, add it in little by little and keep an eye on the scope. If you start to see jitter or "missed" pulses then you're "overloading" the PIC - ie interrupting to fast. Keep the code in the ISR as tight and short and possible. Think thru it, is there any other way to achive this or that to make this execute faster. Every cycle counts here. Verify with the scope, the pulsewidth shows the execution time of the ISR.
Trying to make a 3-phase inverter when you're new to PICs are quite a challange - as you probably/hopefully know by now - take baby steps.
Bookmarks