CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

18F2520 Timer Setup Problem
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

18F2520 Timer Setup Problem
PostPosted: Sun Jul 05, 2009 2:42 pm     Reply with quote

I usually use the 18F452, but today it's the 18F2520.
Even with the oscillator disconnected, the output pin provides a 59% duty cycle 136us period square wave. If the pin address is changed the outputs do change to the new pin. If the delay is increased the output does not change, thought dropping it drastically, from 70ms to70 us, does increase the period by about 10%.

Perhaps I must disable the internal osc?
Here's some of the code.
Thanks for any help.

Do you perhaps know of example code using the 18F2520 and an external osc?
Code:
#include "18F2520.h"
#device icd=true
#device *=16 ADC=8
#fuses HS,NOPROTECT,NOLVP,NOWDT,PUT,NOBROWNOUT
#use delay(clock=40000000) //(40Mhz)
#include <stdio.h>
#include <string.h>
...
output_low(Pin_A0);
delay_ms(70);
output_high(Pin_A0);
delay_ms(70);
...
Ttelmah
Guest







PostPosted: Sun Jul 05, 2009 3:04 pm     Reply with quote

The oscillator pin is probably just floating, and generating some random speed connected to some external signal.
_HS_, does not support 40MHz. The maximum _oscillator_ supported by the chip, is 25MHz. To go above 25MHz, you need to use a lower frequency crystall, and the PLL, or an external oscillator module.

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 3:08 pm     Reply with quote

Do you have a 10 MHz crystal (and associated capacitors) connected to
the oscillator pins of the PIC ? If so, the "H4" fuse cause the PIC to run
at 40 MHz. Example:
Code:

#include <18F2520.h>
#fuses H4,NOPROTECT,NOLVP,NOWDT,PUT,NOBROWNOUT
#use delay(clock=40000000) //(40Mhz)

//==========================================
void main()
{

while(1)
  {   
   output_low(PIN_A0);
   delay_ms(70);
   output_high(PIN_A0);
   delay_ms(70);
  }
}
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 3:55 pm     Reply with quote

Using a 20MHz crystal, instead of the 40MHZ Oscillator, doesn't improve anything. Produces signal is now 7us instead of 80us.

Actually, if I have NO Osc or TX connected, it still has the same timing. Something Internal is triggering the uC. How do I turn it off?


Last edited by R0B0T1CS on Sun Jul 05, 2009 4:25 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 4:10 pm     Reply with quote

How do you know this ? Are you testing this project on real hardware
with an oscilloscope ? Or is this a Proteus project ? What is your
compiler version ?
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 5:17 pm     Reply with quote

Actually, if I have NO Osc or TX connected, it still has the same timing. Something Internal is triggering the uC. How do I turn it off?
I'm using a scope on a real circuit.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 5:21 pm     Reply with quote

1. Post the test program that you are using now. Don't post code
fragments. But make it be a very small program.

2. Post if you are using an external crystal or oscillator. Post the
frequency that is written on the crystal or oscillator.

3. Post your compiler version.
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 7:38 pm     Reply with quote

pcwh 3.209

The PIC functions the same even when no OSC is connected.
Code:
#include "18F2520.h"
#device icd=true
#device *=16 ADC=8
#fuses HS,NOPROTECT,NOLVP,NOWDT,PUT,NOBROWNOUT
//////NOWDT,NOMCLR,INTRC_IO,NOPBADEN,NOBROWNOUT,PUT,NOLVP
#use delay(clock=20000000) //(20Mhz)
#include <stdio.h>
#include <string.h>
//SETUP_TIMER0(0)

void main()
{

while(1)
  {
   output_low(Pin_A0);
   delay_ms(70);
   output_high(Pin_A0);
   delay_ms(70);
  }
}


Last edited by R0B0T1CS on Sun Jul 05, 2009 11:22 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 8:08 pm     Reply with quote

Quote:
#fuses HS,NOPROTECT,NOLVP,NOWDT,PUT,NOBROWNOUT
NOWDT,NOMCLR,INTRC_IO,NOPBADEN,NOBROWNOUT,PUT,NOLVP

You are using two different oscillator fuses. This is wrong. You should
only use one oscillator setting.

Try a simple test program and see if it works:
Code:

#include <18F2520.h>
#fuses INTRC_IO,NOPBADEN,NOBROWNOUT,NOMCLR,PUT,NOLVP
#use delay(clock=4000000)

//==========================
void main()
{

while(1)
  {
   output_low(Pin_A0);
   delay_ms(70);
   output_high(Pin_A0);
   delay_ms(70);
  }

}
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 10:24 pm     Reply with quote

no change.
I haven't even told the program to "run" and the output is being provided. hitting "run" in the icd control gui changes nothing.

Also, if 2 osc setup statements is "wrong", then just how would you use H4 and be able to tell the uc what rate the osc*4 would be?

BTW, thanks for your help Smile
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 10:49 pm     Reply with quote

1. What development environment are you using ? CCS IDE or MPLAB ?

2. Did you build your own board, or did you buy it ? If you bought it,
post the manufacturer and model number.

3. Have you ever made this PIC do anything successfully ?
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Sun Jul 05, 2009 11:21 pm     Reply with quote

wait, wait... now I see.
The second osc statement you highlighted, which I somehow missed seeing before, is extra code I missed commenting out of what I posted here.
//NOWDT,NOMCLR,INTRC_IO,NOPBADEN,NOBROWNOUT,PUT,NOLVP

I'm using ccs ide.
I'm building the circuit myself, but I've done this a few times before.
This is my first time using the 2520.

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 12:51 am     Reply with quote

You have edited your post from what it was.
Do you still have a problem ? If so, post your current test program.
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 7:33 am     Reply with quote

If the 18F2520 is programmed and powered, whether it is being dissabled by the ICD or not, it runs the same and produces a wave form which is ~140us square wave with 59% duty cycle.
PCWH 3.209

Code:
#include "18F2520.h"
#device icd=true
#device *=16 ADC=8
#fuses HS,NOPROTECT,NOLVP,NOWDT,PUT,NOBROWNOUT
#use delay(clock=20000000) //(20Mhz)
#include <stdio.h>
#include <string.h>

void main()
{
while(1)
{
   output_low(Pin_A0);
   delay_ms(70);
   output_high(Pin_A0);
   delay_ms(70);
 }
}

It seems to me like a 2520 - specific compiler timer - configuration error.

Oooooh, a challenge :\
Thanks,
R
R0B0T1CS



Joined: 05 Jul 2009
Posts: 8

View user's profile Send private message

PostPosted: Mon Jul 06, 2009 9:48 am     Reply with quote

Hey, I got it working Smile ... half of the time :\
Here's how to make the 18F2520 function properly at 40Mhz.

1-In the ICD interface window I used the "Advanced" tab to manually set the uC ID to 18F2520.
2-I had jumpered the internal pins in the ICD-U40 so that it would power itself and the target. So I disconnected that jumper.
3-Using your 4MHz code the timing was correct for about 2 minutes, then stopped working properly. Does not dissable when told.
-Setting to 20MHz with a 20MHz crystal it bahaves as if I'm instead connecting a 1MHz crystal. Does not dissable when told.
-Setting to 40MHz with a 40MHz oscillator briefly opperate with the proper timing, during the first test, and dissables when told via the ICD interface (run program / stop program). Note that the data sheet indicates 25MHz but the Microchip site indicates 40MHz as the max frequency.
-Setting to 1MHz with a 40MHz oscillator it opperates with the proper timing, NOW during the second test, and dissables when told via the ICD interface (run program / stop program).

Upon Power-up, there is ~50/50 chance that the 18F2520 will use proper timing or attempt to multiply the input osc frequency by 40. Cause and solution still unknown to date (07/18/09). I will post solution when found.

Note that the data sheet indicates 25MHz but the Microchip site indicates 40MHz as the max frequency.

I have yet to test the output frequency of the CCP modules with respect to this hack (1MHz to get 40Mhz.

PCWH 3.209 must have some timer bug associated with the 18F2520. I have had trouble with other 18Fxxxx chips (newer 4 digit parts). Perhaps I should go back and try those again with the max 40MHz Osc attached instead of 10MHz & H4.

Code:
#include "18F2520.h"
#device icd=true
#device *=16 ADC=8
#fuses HS,NOPROTECT,NOLVP,NOWDT,PUT,NOBROWNOUT
#use delay(clock=1000000) //(for 40Mhz)
#include <stdio.h>
#include <string.h>

void main()
{
while(1)
{
output_low(Pin_A0);
delay_ms(70);
output_high(Pin_A0);
delay_ms(70);
}
}

Thanks for your help!!!
R


Last edited by R0B0T1CS on Sun Jul 19, 2009 9:22 pm; edited 3 times in total
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
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