|
|
View previous topic :: View next topic |
Author |
Message |
scottc
Joined: 16 Aug 2010 Posts: 95
|
Pic18f2431 running at 40Mhz issues with CCP1 PWM. |
Posted: Sat Nov 13, 2010 12:55 am |
|
|
Hi guys, having some issues with a 18f2431 thats running with the 4xpll
enabled to give a 40Mhz Internal clock from a 10Mhz crystal oscillator.
Here is a snip of working code. This code works fine with the 4x pll
enabled.
Code: |
Void Menu_System(void)
{
if (count==2)
{
encoder_mhz();
}
if (changed==true)
{
changed=false;
write_display();
}
}
void main(void)
{
set_tris_b(0b00001101); //Port B I/O Config
set_tris_c(0b11000000); //Port C I/O Config
mhz=100;
khz=0;
LCD_START();
count=2;
changed=true;
while (true)
{
menu_system();
}
}
|
Now since I am using a LCD I use the ccp with pwm to adjust the backlight
The following code Fails at 40Mhz with the 4x pll, Main just will not run.
The CCP does appear to run ok. The code works fine At 10Mhz.
Everything works as intended.
Code: |
Void Menu_System(void)
{
if (count==2)
{
encoder_mhz();
}
if (changed==true)
{
changed=false;
write_display();
}
}
void main(void)
{
set_tris_b(0b00001101); //Port B I/O Config
set_tris_c(0b11000000); //Port C I/O Config
mhz=100;
khz=0;
LCD_START();
count=2;
changed=true;
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_16, 255, 10); //PWM = 245 Hz (with a 40 MHz clock)
Backlight=50;
set_pwm1_duty(Backlight); //Init PWM TO Known State
while (true)
{
menu_system();
}
}
|
Running from the 10Mhz Crystal I use
Code: | #use delay(clock=10M, crystal)
|
Enabling the 4x pll I use
Code: | #USE delay(crystal=10Mhz, clock=40Mhz)
|
Now I had a similar problem using a pic18f2331, which is the same as the
pic18f2431, 2431 has more flash. In the case of the 2331 none of the code
would work at 40Mhz. Everything works good at 10Mhz
I wonder if the 18f2431 is really designed to work up at 40Mhz.
As a side note, I ran the above code on a PIC18F26K20 at 64Mhz using the internal pll with internal 16Mhz OSC and it worked without issues.
Currently using v4.114 compiler. Any ideas as to what to look for ?
Thanks Scott |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19559
|
|
Posted: Sat Nov 13, 2010 3:15 am |
|
|
There is a statement 'wrong' in your remarks. The setup, won't give 245Hz, but about 2450Hz.
The _postscaler_, does not affect the frequency of the PWM, but the frequency of the interrupt. Your PWM, is being set to run at:
40000000/(4*256*16)Hz = 2441Hz.
Now, don't know if this affects your hardware, but having remarks wrong, never helps. The Timer interrupt, will come at 1/10th this frequency (close to your 245Hz), but the actual PWM, runs 10* faster than you expect.
Now, there are known 'issues' with some LCD's and faster operation, requiring delays to be added to the standard LCD code. While this would appear to be 'ruled out' by your successful operation at 64MHz, you need to perform some better diagnostics, and actually find out what is hanging, rather than assuming it is the timer or PWM.
The 2431/21, have a lot of errata, most don't seem to apply to your code (auto baud on the UART, a lot of stuff for the PCPWM, but a few are 'exotic' (smoothing on Avdd, error with program memory writes, and a fault with the DAW instruction. While these would not appear to apply, it suggests some significant internal problems, that might only appear at higher frequencies.
You need to perform _basic_ diagnostics. try just running the PWM, without all the other code. Does this work, if so, then you can rule this out and move to the next component. Try basic 'hello world' tests of the LCD. Does this work at the higher speed. etc..
This is the fundamental 'core' of debugging.
Best Wishes |
|
|
scottc
Joined: 16 Aug 2010 Posts: 95
|
|
Posted: Sat Nov 13, 2010 3:15 pm |
|
|
Hi Ttelamh, Thanks for pointing out the Timer interrupt. I assumed that
because the ISR is running at 245Hz That was the actual PWM frequency.
I am about ready to Let the "White Smoke" out of this part and call it a
day. I verified the routines running at 40Mhz With the 4xpll up scaling
to 40Mhz from 10Mhz.
On their own the LCD routine works and the PWM also works. I can slow
down the LCD routine to be dog slow on writes and still both routines
will not run correctly at 40Mhz with the 4x pll. I reduce the clock speed
to 10Mhz and everything works great.
I honestly think that this silicon is bad, or very borderline at the upper
end of its frequency limit.
I am not too familar with debugging, but I think one area to look at is
the OSCON register to verify it is indeed configured correctly. I have MPLAB/PicKit 3 and CCS ICD-U64 with pcwh, so any pointers on how to locate the oscon register with those tools would be a big help.
I verified the PSU and grounds. They appear to be good.
Thanks Scott. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|