Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18F46K20 timing error

Status
Not open for further replies.

camerart

Well-Known Member
Hi,
Here is a program on an 18F46K20 PIC

There is a LOOP around the START UP LEDS, which should flash ON/OFF 1/sec, the LEDs flash app 1 /4sec.

I've tried to set the timing registers, and notice to get 32MHz x4 is needed, then in T1CON BIT 1 the internal option divides by 4, which seems to defeat the object. The LEDs flash app 1 in 4sec

T1CON = %11111101 '7=16BIT, 6=TIMER1 osc 54=1:8, 3=EN OSC, 2=INT, 1=INT osc/4 0=En TMR1
T2CON = 0
T3CON = 0
OSCCON = %01101110 '7=sleep 654=Osc frequency 8MHz 3=CONFIG1 REG 2=stable 10=INT OSC
OSCTUNE.PLLEN = 1 'OSCx4

Any ideas please?
Camerart.
 

Attachments

  • 18LF46K20 32Mhz RX 2XPIC COMPASS HC-12 110918 0930 TMR1.bas
    17.1 KB · Views: 353
  • OSCCON.jpg
    OSCCON.jpg
    168.3 KB · Views: 331
  • T1con.jpg
    T1con.jpg
    277.6 KB · Views: 345
T1CON bit 1 should be 0
-> Timer1 clock source is internal oscillator.
But I think the serial and timer1 interrupts influence on Waitms delays
making them longer.

Edit: I did not notice, that only the loop is running, so timer1 and interrupts don't influence on timings.
 
Last edited:
T1CON bit 1 should be 0
-> Timer1 clock source is internal oscillator.
But I think the serial and timer1 interrupts influence on Waitms delays
making them longer.

Edit: I did not notice, that only the loop is running, so timer1 and interrupts don't influence on timings.
Hi I,
From the program posted :

T1CON = %11111101 '7=16BIT, 6=TIMER1 osc 54=1:8, 3=EN OSC, 2=INT, 1=INT osc/4 0=En TMR1
C.
 
Are you running from an ICSP ? .... The reason I ask, is that some PIC's are aware of a Reset Condition versus a Cold Start. Some ICSP will make the PIC think it started from a Reset after programming. My PicKit3 does this.

PDF Reference:
https://ww1.microchip.com/downloads/en/DeviceDoc/40001303H.pdf

From the PDF page 27 .... "On device Resets, the output frequency of the internal oscillator is set to the default frequency of 1 MHz."

Also see page 33

I'm not familiar with this particular PIC, but I have seen plenty of others... I usually do something at the very beginning of my code that forces or resets the the PIC to the desired speed.
 
Why have you posted a file that's nearly 700 lines long? Post a file with only the bits that aren't working.

Have you solved this now?

Mike.
 
Why have you posted a file that's nearly 700 lines long? Post a file with only the bits that aren't working.

Have you solved this now?

Mike.
Hi M,
In #1 didn't I write what you are requesting?

I posted the whole program, in case anyone interested in simulating it in Oshonsodft, could do.
C.
 
Are you running from an ICSP ? .... The reason I ask, is that some PIC's are aware of a Reset Condition versus a Cold Start. Some ICSP will make the PIC think it started from a Reset after programming. My PicKit3 does this.

PDF Reference:
https://ww1.microchip.com/downloads/en/DeviceDoc/40001303H.pdf

From the PDF page 27 .... "On device Resets, the output frequency of the internal oscillator is set to the default frequency of 1 MHz."

Also see page 33

I'm not familiar with this particular PIC, but I have seen plenty of others... I usually do something at the very beginning of my code that forces or resets the the PIC to the desired speed.
Hi B,
Yes, ICSP.
The PIC seems to start ok, and I looked farther into this, but got a bit confused. I tried erasing with Pickit3 and MPLAB, looked to the code and it was erased, re-programmed and still the same.

I googled, and found my similar question i June.

I'm puzzled about DEFINE CLOCK_FREQUENCY and PLLEN. OSCCON is set to 8MHz then PLLEN is set x4. I changed the CLOCK_FREQUENCY from 32MHz to 8MHz and the LEDs now flash correctly. Is this the correct setting?
C.
 
Clock_frequency should be defined as the real frequency.
Maybe the real frequency is 8Mhz, not 32Mhz you try to set.
 
Hi,
It appears to be working ok now, after 8MHz setting, thanks.

Unless this is two wrongs making a right?
C.
 
Clock_frequency should be defined as the real frequency.
Maybe the real frequency is 8Mhz, not 32Mhz you try to set.
Hi J,

Yes, I think the CLOCK_FREQUENCY should be set to the OSCCON setting. I presume that to test the PLLEN x4 is working, the OSC output PIN should be set and READ with an oscilloscope?

It seems to be working ok now, thanks to all.
C.
 
If you are trying to debug something then write the minimum code. Posting 700 lines of code means that no one has time to go through it all. Yes, you posted a snippet but you assume that this is where your error lays - it can be anywhere in your 700 lines. Post code that is less than 50 lines that shows the error and people may be able to help.

Mike.
 
If you are trying to debug something then write the minimum code. Posting 700 lines of code means that no one has time to go through it all. Yes, you posted a snippet but you assume that this is where your error lays - it can be anywhere in your 700 lines. Post code that is less than 50 lines that shows the error and people may be able to help.

Mike.
Hi M,
As mentioned, I typed the three offending lines in #1, so that's all you need to read.

I only posted the full program in case anyone wanted it. sorry for the confusion.

C.
 
Last edited:
It seems that, the 4xPLL is not working.
Check with an oscilloscope
Hi J,
Instead of trying the oscilloscope, I had a closer look at OSCCON, and saw that PLLEN only works with (HFINTOSC or LFINTOSC) so I reset OSCCON as image:

Now it's working with Define CLOCK_FREQUENCY = 32, which is, as I recall is similar to what you said in June.

C.
 

Attachments

  • OSCCON.jpg
    OSCCON.jpg
    150.2 KB · Views: 335
If you are trying to debug something then write the minimum code. Posting 700 lines of code means that no one has time to go through it all. Yes, you posted a snippet but you assume that this is where your error lays - it can be anywhere in your 700 lines. Post code that is less than 50 lines that shows the error and people may be able to help.

Mike.
Hi M,
To clarify: I'm not a good enough programmer to be able to write a short test, because I would get very mixed up. In the posted program I commented out as much as I could, while keeping it working, apart from the timing issue.
C.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top