View previous topic :: View next topic |
Author |
Message |
silvanoservitec
Joined: 25 Sep 2010 Posts: 4 Location: Brazil
|
crystal |
Posted: Sat Sep 25, 2010 1:12 pm |
|
|
Friends, I am with this source code.
Used with external crystal oscillator XT.
Circuit works in my one week or more.
And for no reason to swing.
I changed the crystal.
Is connected to a resistor 4k7 MCLR (pin4) to +5 v.
leaving the PWM (pin 8) in series with 1K resistor.
4MHz crystal pin 15 and 16 with 22pf capacitor to GND.
It should be alright.
Because for swinging for no reason.
Internal oscillator is no longer accurate.
I need.
I want one with crystal and 100kHz Where am I wrong? _________________ silvanoservitec
Last edited by silvanoservitec on Sat Feb 05, 2011 12:39 pm; edited 2 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 26, 2010 5:40 pm |
|
|
What is your CCS compiler version ? It's given at the top of the .LST file.
It's a number like 3.249 or 4.112, etc. |
|
|
silvanoservitec
Joined: 25 Sep 2010 Posts: 4 Location: Brazil
|
|
Posted: Sun Sep 26, 2010 6:23 pm |
|
|
Thank you for your attention
PCM Programer.
the compiler version is: "CCS PCM C Compiler, Version 4.068,"
I wonder if this source code.
Is complete and true.
sds
silvanoservitec. _________________ silvanoservitec |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Mon Sep 27, 2010 1:57 am |
|
|
4.068, was 'on the border', where the version 4 compilers, first started to work. For 99% of simple code, this should probably work. However it did have some configuration problems with some chips, and might be giving problems. I haven't kept any of the V4 compilers before 4.070, which was the first that I found would generate pretty much usable code, so can't verify if your version would work. Classic problems for chips like yours, are that the early compilers often don't initialize things like the ADC pins correctly, but this shouldn't affect what you are trying to do.
Now, taking your original code:
Fosc=4MHz.
Timer2 is being fed off 1MHz.
As shown, you have it counting to 10, so should see 100KHz.
The duty cycle though will only be 30% high, not the 50% you refer to.
To change this to work off an external 4MHz crystal, and give 50%, would need:
Code: |
#include <16F818.h>
#fuses XT, NOWDT, MCLR, PUT, BROWNOUT //Switch to using Xtal OSC
#use delay(clock=4000000)
//=============================
void main() {
setup_ccp1(CCP_PWM);
setup_timer_2(T2_DIV_BY_1, 9, 1);
set_pwm1_duty(5); //For 5/10 duty cycle.
while(1);
}
|
Best Wishes |
|
|
silvanoservitec
Joined: 25 Sep 2010 Posts: 4 Location: Brazil
|
|
Posted: Mon Sep 27, 2010 2:34 pm |
|
|
Ttelmah ok thanks, sorry, was my mistake to post.
I made many tests with this code.
and just posting (set_pwm1_duty (3);) I'm using ((5))).
installed version CCS PCM C Compiler, Version 4088
and compiled.
I will write an internal oscillator with pic and test a few days.
I was lost faith in this code.
sds
silvanoservitec _________________ silvanoservitec |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Tue Sep 28, 2010 6:51 am |
|
|
i might have misunderstood but, you mentioned you changed the crystal...
this would change all your timing schemes...
you would need to adjust timers and prescalers... etc...
... that be my first guess....
Ttelmah seems to have solved the timing issues for you.... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
silvanoservitec
Joined: 25 Sep 2010 Posts: 4 Location: Brazil
|
|
Posted: Tue Sep 28, 2010 6:58 am |
|
|
Gabriel, I should have explained badly.
I am using a translator.(portugues-ingles)
I swapped the crystal for another one.
To determine whether the defect was pwm stop generating it.
sds
silvanoservitec _________________ silvanoservitec |
|
|
|