View previous topic :: View next topic |
Author |
Message |
JimHearne
Joined: 06 Apr 2021 Posts: 8 Location: UK
|
16F18425 ADC Frc Oscillator stops running when PIC is warm. |
Posted: Tue Apr 06, 2021 2:30 am |
|
|
Hi All,
I've been on here before but had to re-register as i couldn't get my old logon to work.
We've come across a problem with a product using a PIC 16F18425
I was using the Frc Oscillator as the clock for the ADC
We have just found that when the PIC gets above 40C the frequency of the ADC interrupts drops by half, then half again and when it gets warm enough they stop all together.
When it cools they restart in the same way, at a much lower frequency and then speeds back up to the normal (for this code) 10mS interval.
I hacked the code down to the bare minimum to show the problem.
I would normally have a state machine in the ADC interrupt to read the ADC result , select the next ADC channel and allow it to settle etc.
But you can see the interrupts slowing just from the interrupt toggling the I/O pin.
If i change the ADC clock to use FOSC/8 instead of Frc then it works fine at all temperatures.
Has anybody come across something like this before, or see something silly in this code that would cause it (i can't really think what code would cause a temperature related issue).
Even better has somebody got a PIC 16F18425 they could try this code on and warm up the PIC. I am using the QFN package.
To eliminate some obvious questions:
The 5V is rock steady, usual filter caps etc.
The PIC is still running when this happens, only the ADC interrupt slows and stops.
It's not restarting on the WDT.
Code: | #include <16F18425.h>
#device adc=12
#use delay(internal=8mhz,RESTART_WDT)
#fuses RSTOSC_HFINTRC, PUT_64MS, BROWNOUT, WDT, NOMCLR, PROTECT, BORV27, PPS1WAY, NOCLKOUT, STVREN, NODEBUG, NOLVP,NOWRT,NOBOOTBLOCK,SAF
#int_TIMER0
void timer0_isr(void)
{
set_timer0(64911); // reload for 10ms period
}
#int_AD_THRESHOLD
void INT_AD_THRESHOLD_int(void)
{
output_toggle(PIN_C3);
}
void main(void)
{
set_timer0(64911);
setup_timer_0(T0_INTERNAL | T0_DIV_32 | T0_16_BIT); // 10ms interval
setup_adc_ports(sAN16, VSS_VDD);
setup_adc(ADC_BURST_AVERAGE_MODE | ADC_CLOCK_INTERNAL | ADC_TAD_MUL_255 | ADC_THRESHOLD_INT_END_OF_CALCULATION, 4, 16); // this stops working if PIC is warmed.
// setup_adc(ADC_BURST_AVERAGE_MODE | ADC_CLOCK_DIV_8 | ADC_TAD_MUL_255 | ADC_THRESHOLD_INT_END_OF_CALCULATION, 4, 16); // this works fine
set_adc_trigger(ADC_TRIGGER_TIMER0);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_AD_THRESHOLD);
enable_interrupts(global);
while ( 1 )
{
restart_wdt();
}
}
|
Many thanks,
Jim Hearne
Last edited by JimHearne on Tue Apr 06, 2021 3:12 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 06, 2021 2:53 am |
|
|
You should never use ADC_CLOCK_INTERNAL. Data sheet tells you that this
will result in inaccurate readings if the processor is running above 1MHz.
Don't use this.
Why would you want to?. |
|
|
JimHearne
Joined: 06 Apr 2021 Posts: 8 Location: UK
|
|
Posted: Tue Apr 06, 2021 3:01 am |
|
|
Hi Ttelmah,
Thank you for your reply.
I used the Frc as I knew of no reason not to use it.
I would be grateful if you could point me at the section in the 16F18425 datasheet that mentions not using it above 1mhz FOSC as i can't find it.
Many thanks,
Jim Hearne |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 06, 2021 3:46 am |
|
|
Historically this is in the application note for the ADC. Generally most
of the data sheets do mention it as well, but the 16F18425 doesn't.
However it does tell you that using Fosc/x option will if correctly
setup give better timings, and there is a warning on Frc that this may
give unexpected delays when setting the control bits.
Generally the issue is that because this results in the ADC timing being
asynchronous to the processor, you can get erratic results, unless you
put the processor to sleep for the conversion... |
|
|
JimHearne
Joined: 06 Apr 2021 Posts: 8 Location: UK
|
|
Posted: Tue Apr 06, 2021 3:48 am |
|
|
Ok, after looking at some datasheets for older PIC i can see on some that there is this mention of not using Frc with a clock above 1mhz below the ADC clock table.
On other PIC's it's in the Errata.
For the 16F18425 there is no mention in the datasheet or the Errata.
I tried our board at 1, 2 & 4mhz clock and indeed the problem doesn't occur with Frc when the PIC is warmed.
At 16mhz clock the Frc does not run at all.
Looks like Microchip forgot to add this warning for the 16F18425
Many thanks,
Jim |
|
|
JimHearne
Joined: 06 Apr 2021 Posts: 8 Location: UK
|
|
Posted: Tue Apr 06, 2021 3:50 am |
|
|
Sorry, posted my last message while you were replying.
An expensive lesson learnt.
Thanks,
Jim |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 06, 2021 3:59 am |
|
|
It is interesting, since it suggests this chip should have an erratum about
this. It suggests that the timing issue mentioned may become really bad
when the chip is warm... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Apr 06, 2021 4:55 am |
|
|
heck no wonder the PIC complains..
40*C is 104*F on thsi side of the pond !
I don't like to work at that temperature !!
As Mr. T pointed out, it's USUALLY in the datasheet, but some newer PICs can run the ADC clock above 1M.
One problem we see here are programs with 'internal' selected as it's the default for the 'wizard',even though PIC clock is >1M. |
|
|
JimHearne
Joined: 06 Apr 2021 Posts: 8 Location: UK
|
|
Posted: Tue Apr 06, 2021 5:07 am |
|
|
The PIC is supposed to work between -40°C to 85°C so 40°C should be fine.
Anyways, this was found during testing , it normally will be at close to ambient
air temperature, though in some parts of the world it could be close to 40.
Jim |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 06, 2021 5:48 am |
|
|
Generally, I'd say except for the DsPIC's, you should always run the ADC off
an Fosc division. This also allows you to select a faster clock which
improves the whole ADC behaviour.
It is actually something I find quite annoying, that several of the CCS
examples select the internal ADC clock. Whoever wrote these was probably
a student with no knowledge of the PIC hardware.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9229 Location: Greensville,Ontario
|
|
Posted: Tue Apr 06, 2021 7:02 am |
|
|
naaaaa....
they used the 'wizard' !! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19518
|
|
Posted: Tue Apr 06, 2021 7:11 am |
|
|
Aaaargh!.
Whimper.... |
|
|
|