|
|
View previous topic :: View next topic |
Author |
Message |
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Tue Sep 06, 2016 3:20 am |
|
|
Ttelmah wrote: | More likely the oscillator is not actually running. The chip has a feature 'fail safe clock monitor', that if the main oscillator does not start, it'll attempt to use the internal source. |
It seem to use ext OSC because if I short it then the chip stops working. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Tue Sep 06, 2016 3:34 am |
|
|
Measure the time reasonably accurately.
Do ten pulses, and use a stopwatch.
Just something like:
Code: |
for (count=0;count<10;count++)
output_toggle(PIN_xx); //whatever pin you want.
|
The actual time can often tell you what clock the system really is running off.
Other thing to try is get rid of H4. So set your clock as 10MHz, and select HS, instead of H4. If the system then runs at something like 3MHz, it tells you exactly where the problem is (your crystal is not resonating at the frequency it should...). |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Wed Sep 07, 2016 1:50 am |
|
|
So, one second (1000ms) is 3.x seconds in real. Crystals are 100% spot on, scope goes clear 10Mhz. So it is software related. I search and shall report if I find it. I had issues with H4 in the past, some chips using HSPLL worked nicely but others where H4 was used it was always a problem. I wonder if there is some specific way to call it.
Fuses do not leave much to play with:
Code: |
//////// Fuses: LP,XT,HS,RC,EC,EC_IO,H4,RC_IO,INTRC_IO,INTRC,NOFCMEN,FCMEN
//////// Fuses: NOIESO,IESO,PUT,NOPUT,NOBROWNOUT,BROWNOUT_SW,BROWNOUT_NOSL
//////// Fuses: BROWNOUT,BORV45,BORV43,BORV27,BORV21,NOWDT,WDT,WDT1,WDT2
//////// Fuses: WDT4,WDT8,WDT16,WDT32,WDT64,WDT128,WDT256,WDT512,WDT1024
//////// Fuses: WDT2048,WDT4096,WDT8192,WDT16384,WDT32768,CCP2B3,CCP2C1
//////// Fuses: NOPBADEN,PBADEN,NOLPT1OSC,LPT1OSC,NOMCLR,MCLR,NOSTVREN
//////// Fuses: STVREN,NOLVP,LVP,NOXINST,XINST,DEBUG,NODEBUG,PROTECT
//////// Fuses: NOPROTECT,CPB,NOCPB,CPD,NOCPD,WRT,NOWRT,WRTC,NOWRTC,WRTB
//////// Fuses: NOWRTB,WRTD,NOWRTD,EBTR,NOEBTR,EBTRB,NOEBTRB |
_________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Wed Sep 07, 2016 4:36 am |
|
|
A problem with H4, would give you a factor of 4 error, not 3. As I have already asked, have you actually tried without H4, to see exactly what you are genuinely seeing?. Have you tested at the same time as your scope is attached?. One of the commonest types of fault, often disappears when the scope is attached (crystal being slightly overdriven, and locking onto a sub harmonic). The PLL's in particular _are_ sensitive to the crystal being overdriven (more so than the standard oscillator). This behaviour is why MicroChip recommend a resistor in series with the crystal, if the crystal gain is high (particularly strip cut crystals). This wants to be as large as you can go and the crystal still start to oscillate reliably. Something like 200R is typically fine. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Thu Sep 08, 2016 1:36 am |
|
|
Hi, yes I have tried, so on 10x 100MHz oscilloscope is perfect.
The HS is 3 times slow too. I will put resistor in and have a look, it is 10MHz 20p crystal. What resistance would I stick in? On both ends or just one end (OSC1, OSC2)? _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19540
|
|
Posted: Thu Sep 08, 2016 1:58 am |
|
|
Between either PIC pin, and the crystal/capacitors.
Your crystal is almost certainly designed as a third overtone oscillator. Overdrive it, and you lock onto the fundamental. If you look carefully at the scope waveform, you will probably see that it is not a nice even 10Mhz, but every third cycle is larger. It is this that the PIC is locking onto. Start with the resistor quite large. If the PIC doesn't start, halve it. You want the largest resistor that allows the oscillator to reliably start. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Thu Sep 08, 2016 2:02 am |
|
|
thnx will do, I let you know what I find, it is FS10.00P by the way. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1909
|
|
Posted: Thu Sep 08, 2016 6:16 am |
|
|
Linuxbuilders wrote: | Hi, yes I have tried, so on 10x 100MHz oscilloscope is perfect.
The HS is 3 times slow too. I will put resistor in and have a look, it is 10MHz 20p crystal. What resistance would I stick in? On both ends or just one end (OSC1, OSC2)? |
My standard osc circuit for dsPICs is a 160R series resistor (a single resistor). |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Sep 09, 2016 1:52 am |
|
|
Abilities of this processor are magical, first I was able to run it on 20MHz OSC in HS mode, second running it on internal RC is doing exactly the same and it is 3 times slower. Resistors do help with nothing. I am not totally puzzled, is this Microchip an issue here or some dodgy code from CCS, of course CCS does not care to respond on question as long I pay them $200! Why would they bother to support their own product?! Anyway it is seriously dodgy now when MCU does not support 20MHZ but I can run it on this OSC and then whatever magic I do it is still 3 times slower, it cannot be hardware if running on internal oscillator. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 09, 2016 1:56 am |
|
|
1. Post the complete code of your current test program that is failing.
and ideally, for more help,
2. Post your board schematic.
3. Post a hi-res, in-focus photo of your board or test setup. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Sep 09, 2016 1:57 am |
|
|
Is there any way to set this manually on registers? I would then ignore CCS compiler in this section and set the clock manually. I have no idea how to do it. If I would set registers manually to internal clock on lets sat 1MHz then will not rely on compiler and then will know if the code is wrong or chip definition is wrong or the chip is wrong. Thnx _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Sep 09, 2016 2:03 am |
|
|
PCM programmer wrote: | 1. Post the complete code of your current test program that is failing.
and ideally, for more help,
2. Post your board schematic.
3. Post a hi-res, in-focus photo of your board or test setup. |
I will rewrite the code new first to bare minimum so it is 100% spot on.
Regardless of the board structure and the circuit the RC running on internal clock would not be affected by the circuit anyway. I have de-soldered the oscillator completely to prove that it is running on internal RC. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Sep 09, 2016 2:15 am |
|
|
Default bare code out of wizard is ok. So there is something happening once I start adding IRQ, etc. I will find what does slow down the system and post later on. It will be some function or IRQ causing system overload or something. _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Fri Sep 09, 2016 3:09 am |
|
|
BINGO!
Code: |
setup_timer_0 (RTCC_INTERNAL|RTCC_8_BIT|T0_DIV_1); //WRONG!!!
setup_timer_0 (T0_DIV_1); //CORRECT!!!
|
as per:
Code: |
////////////////////////////////////////////////////////////////// Timer 0
// Timer 0 (AKA RTCC)Functions: SETUP_COUNTERS() or SETUP_TIMER_0(),
// SET_TIMER0() or SET_RTCC(),
// GET_TIMER0() or GET_RTCC()
// Timer 0 Prototypes:
_bif void setup_timer_0(int8 mode);
_bif void set_timer0(int16 value);
|
So it is me and CCS, me because I am an idiot, CCS because they allow illegal statements!
CCS please make your software to higlight illegal statements, copy and paste from one chip to another may not be correct as above and it would be very handy to get compilation ERROR. Thank you for listening here! _________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
Linuxbuilders
Joined: 20 Mar 2010 Posts: 193 Location: Auckland NZ
|
|
Posted: Wed Sep 14, 2016 1:42 am |
|
|
To make it easy (sort of):
http://marianlonga.com/pic-timers-with-blinking-led/
Code: |
Tosc = 1/Fosc = 1/40000000 = 0.000000025s = 25ns a TICK => 4x25ns = 100ns an INSTRUCTION CYCLE => (Tpresc = PRESC x Tins = 1 x 100ns = 100ns )
Ttmr = RES x Tpresc = 256 (8bit) x 100ns = 25.6us
where
(8bit) set timer 0 parameters (256 times and resets) 40000000Hz / 4 = 10000000 / 256 = 39062.5Hz => 1s/39062.5Hz = (0.0000256) 25.6us * 256 = 0.0065536s = 152 TICK for 1s
|
_________________ Help "d" others and then you shell receive some help from "d" others. |
|
|
|
|
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
|