|
|
View previous topic :: View next topic |
Author |
Message |
JCasals
Joined: 12 Oct 2009 Posts: 6
|
Use Delay (clock=xxx ) speed problems |
Posted: Thu Sep 12, 2013 7:28 pm |
|
|
Hi All,
I am a electronic Eng but not a programmer therefore the programing issue is a little tricky for me, but i have some experience in CCS complier.
So I have a program running OK in a PIC18F87J11 running OK and I change it to a OLIMEX board.
https://www.olimex.com/Products/PIC/Proto/PIC-P67J60/resources/PIC-P67J60-REV-A-sch.gif
With the correct driver but the speed using the #use delay(clock = 25M) is like putting 25 Hz to the board. When I turn down the speed in the statement to 32500 it start to runs OK.
CCS PCWHD Compiler
Ver 4.110 1994-2013
Code: |
#include <18F67J60.H>
#device ADC=10
#use delay(clock=32500)
#fuses HS,NOWDT,NOPROTECT,NODEBUG, NOETHLED
#use rs232(baud=0,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define LED0 PIN_B4
#define BUTTON PIN_B3
void led_on ();
void led_off ();
void led_on()
{
output_low(LED0);
}
void led_off()
{
output_high(LED0);
}
void main()
{
led_on();
delay_ms(500);
led_off();
while (1)
{
led_on();
delay_ms(1000);
if (input(button)==0 )
{
led_on();
delay_ms(20000);
}
led_off();
delay_ms(1000);
}
}
|
Thanks in advance for the help!! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Thu Sep 12, 2013 8:53 pm |
|
|
OK, if I understand you correctly the code is running at the wrong speed.
Below is a simple test to see if the oscillator is running at the right speed.
The code below assumes you are using a 25MHz crystal. The LED
on B4 should blink at a 1Hz rate.
Does it?
Code: | #include <18F67J60.H>
#use delay(clock=25000000)
#fuses HS, NOWDT
void main()
{
while (1)
{
output_toggle(PIN_B4);
delay_ms(500);
}
} |
If it does not the crystal oscillator is not working correctly and PIC is
going to the fail safe internal 31khz oscillator mode. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
JCasals
Joined: 12 Oct 2009 Posts: 6
|
|
Posted: Fri Sep 13, 2013 7:29 am |
|
|
Dear Dyeatman,
Thanks for your prompt reply and your understanding is correct.
I guess that your last comment is the answer
"If it does not the crystal oscillator is not working correctly and PIC is
going to the fail safe internal 31khz oscillator mode."
I was starting to work in a 2 PIC configuration with a I2C communication and two LCD 4x20 that was starting to respond and suddenly the Olimex crashed and no more response at all, therefore before sending the board to the garbage an have it a try and realized that it was alive but at 31Khz clock.
I guess something happened to the main clock, according to the manual
• Fail-Safe Clock Monitor: This option constantly
monitors the main clock source against a reference
signal provided by the internal oscillator. If a clock
failure occurs, the controller is switched to the
internal oscillator, allowing for continued low-speed
operation or a safe application shutdown.
• Two-Speed Start-up: This option allows the
internal oscillator to serve as the clock source
from Power-on Reset, or wake-up from Sleep
mode, until the primary clock source is available.
so I will check the main clock if something has happen since I guess therefore is no way to configure and force the main clock.
Thanks
Javier |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19498
|
|
Posted: Fri Sep 13, 2013 8:45 am |
|
|
You can 'force' the main clock, but if it isn't working, then the chip will just do nothing.
NOFCMEN, NOIESO, HS, NOXINST, NOWDT,NOPROTECT,NODEBUG, NOETHLED, STVREN, PRIMARY
Some compiler versions require you to explicitly select the 'primary' oscillator. Hence have included this.
Best Wishes |
|
|
|
|
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
|