pragma target clockouten issue?

19 views
Skip to first unread message

vsurducan

unread,
Dec 14, 2024, 6:11:37 AM12/14/24
to jal...@googlegroups.com
Hi Rob,
I'm trying to understand the PWM in PIC12F1572, for which the pwm library can not be used.

I need to see the system clock.
The problem is that I can not make it visible on clockout pin. The following code should do it?

include 12f1572                     -- target PICmicro
--
;pragma target clock    32_000_000       -- oscillator frequency
pragma target clock    8_000_000       -- oscillator frequency
--
pragma target OSC      INTOSC_NOCLKOUT           -- internal oscillator
pragma target PLLEN    DISABLED                  -- PLL off
pragma target CLKOUTEN ENABLED                  -- clock output enabled
pragma target WDT      DISABLED                  -- watchdog
pragma target BROWNOUT DISABLED                  -- no brownout reset
pragma target LVP      ENABLED                   -- low voltage programming
pragma target MCLR     EXTERNAL                  -- external reset
--

OSCCON_SCS = 0                      -- select primary oscillator
OSCCON_IRCF = 0b1110                -- 8 MHz
;OSCCON_SPLLEN = ENABLED               -- software PLL on   8x4=32MHz
OSCCON_SPLLEN = DISABLED    - 8Mhz OSC
--
enable_digital_io()                 -- make all pins digital I/O
pin_A4_direction = output ; output osc/4

vsurducan

unread,
Dec 15, 2024, 1:59:14 AM12/15/24
to jal...@googlegroups.com
Ok, pragma target clkouten is programming the configuration word as it should. Reading hex with a programmer it looks ok.
However on the RA4 pin there is no clock/4.

vsurducan

unread,
Dec 15, 2024, 2:29:18 AM12/15/24
to jal...@googlegroups.com
Solved in a weird mode. The following code is sending OSC/4 on clkout pin if A4 is ON inside a loop.
Without a loop, A4 is permanently low.

include 12f1572                     -- target PICmicro
--
;pragma target clock    32_000_000       -- oscillator frequency
pragma target clock    8_000_000       -- oscillator frequency
--
pragma target OSC      INTOSC_NOCLKOUT           -- internal oscillator
pragma target PLLEN    DISABLED                  -- PLL off
pragma target CLKOUTEN ENABLED                  -- clock output enabled
pragma target WDT      DISABLED                  -- watchdog
pragma target BROWNOUT DISABLED                  -- no brownout reset
pragma target LVP      ENABLED                   -- low voltage programming
pragma target MCLR     EXTERNAL                  -- external reset
--

OSCCON_SCS = 0                      -- select primary oscillator
OSCCON_IRCF = 0b1110                -- 8 MHz
;OSCCON_SPLLEN = ENABLED               -- software PLL on   8x4=32MHz
OSCCON_SPLLEN = DISABLED    - 8Mhz OSC
--
enable_digital_io()                 -- make all pins digital I/O
pin_A4_direction = output      -- output osc/4
alias  clkout       is pin_A4      -- alias for clkout pin

forever loop
   clkout = ON
end loop

Rob Hamerling

unread,
Dec 15, 2024, 5:28:42 AM12/15/24
to jal...@googlegroups.com

Hi Vasili,

Not about clockout, but there is an open Jallib issue (#208) with respect to PWM libraries. It may contain information that could be of help to you.   A few years ago I made some 'private' libraries, to be able to use PWM with 16f161x, 16f184xx, 16f188xx, 18f27k40. I don't know if these are usable for the 12F1572. If you are interested I could send these to you.

Regards, Rob_H!
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/jallib/CAM%2Bj4qtqos%3DsRusP0SVrcELXKuOOgCgETpza6cW_v4vWj4%3DwmA%40mail.gmail.com.

--
Rob Hamerling, Vianen, NL

Rob Hamerling

unread,
Dec 15, 2024, 9:41:51 AM12/15/24
to jal...@googlegroups.com

Just tested the jallib blink sample (which is running at 4 MHz). At pin_A4 see a freq. of 0.998 MHz. So it seems like you have a hardware/wiring problem..
--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

vsurducan

unread,
Dec 15, 2024, 10:10:43 AM12/15/24
to jal...@googlegroups.com
Thx Rob for the feedback!

Well. I've checked the hardware, I have a PCB manufactured in lab, A4 goes to a connector only.
I suspect a defective chip. It also has a weird behavior on PWM.
There are five registers to be written to get the standard PWM mode as shown in the code below.
The PWM clock source was set to Fosc (PWM1CLKCON_CS = 00)
That is meaning according to my understanding that changing the Foc from 8Mhz to 32MHz and keeping the PWM registers unchanged, the PWM frequency will increase 4 times on 32Mhz compared with 8 Mhz.
However, the frequency reamains exactly the same, 10KHz at 8Mhz or 32Mhz ( verified on RA4)  so the PWM clock arhitecture from datasheet seems to be wrong, or the chip is bad.

PWM1CLKCON = 0b00000001 -- No prescaler, divide clk source by 1
PWM1CON = 0b11000000

PWM1PH = 800    --100uS, 0.5duty   
PWM1DC = 1600   ; PWM1_duty = (PWM1DC - PWM1PH)/(PWM1PR+1)
PWM1PR = 1600   ; PWM1_period = (PWM1PR + 1)*prescaler/ PWM1CLK
                ; PWM1CLK = 1/(target_clock/4) =  0.5uS  at 8MHz

vsurducan

unread,
Dec 15, 2024, 10:23:08 AM12/15/24
to jal...@googlegroups.com
Thank you for the offer. I've taken a look at the PIC16F1615 and it has a 10bit PWM.
PIC12F1572 has a 16bit PWM which can be used in too many modes (standard, set on match, center-align). Actually I need the standard PWM just to feed clock for the CWG (complementary waveform generator) and that I partially understand it (see the code posted in the other message).
However I would be interested to see your libraries, I always I'm curious to learn new things, perhaps including them in jallib package would be a good idea.

Vasile


Rob Hamerling

unread,
Dec 15, 2024, 3:12:01 PM12/15/24
to jal...@googlegroups.com

I'm not sure if I fully understand the description of PWM in the datasheet...
You have selected HFINTOSC as clock source for PWM. I think this should be Fosc .
I modified my code to run the 12f1572 at 8MHz with INTOSC_NOCLKOUT and
added your code for PWM (but with Fosc as clock source)
With the following (essential part of the) code I get a 5 KHz signal on pin_A1 with 50% dutycycle:

PWM1CON = 0b11000000        -- enable module and pwm pin, standard pwm mode
PWM1CLKCON = 0b00000000     -- No prescaler, source: Fosc
PWM1PH = 800                -- phase count high (for 50% dutycycle)
PWM1DC = 1600               -- PWM1 phase count
PWM1PR = 1600               -- PWM1 period count
APFCON_P1SEL = 0            -- PWM1 output on pin_A1
pin_A1_direction = OUTPUT


Rob_H

vsurducan

unread,
Dec 16, 2024, 1:46:53 AM12/16/24
to jal...@googlegroups.com
Hi Rob, I have understood some things:
1. Indeed the 12F1572_blink_intosc, with pragma target CLKOUTEN ENABLED returns Fosc/4 on RA4 pin only if forever loop end loop exists. If you expect to have that clock without any repetitive main program (comment the forever loop), it will not be there.
It's possible to be a compiler issue, or a normal behavior of the microcontroller, I do not now.

2. The code below is showing on my scope 10Khz. However I've learned that depends by antialising filter of the scope. 
Can you please take a look on the scope on 20uS time base, on both 8MHz and 32Mhz Clock? I'm curious what you will find.

vsurducan

unread,
Dec 16, 2024, 1:58:09 AM12/16/24
to jal...@googlegroups.com
Rob, your PWM prescaler is set to divide source by 2.
PWM1CLKCON = 0b00000001 -- No prescaler, divide clk source by 1
5KHz it's correct. :)  Yourscope has also antialising filter. :) :)  there is a  Philips scope which does not handle antialising . Or Hantek.

vsurducan

unread,
Dec 16, 2024, 2:08:16 AM12/16/24
to jal...@googlegroups.com
I've look at the wrong register, sorry. 

--  generates 5Khz 50% duty
PWM1CLKCON = 0b00000000 ; Fosc
PWM1CON = 0b11000000
PWM1PH = 800  
PWM1DC = 1600  
PWM1PR = 1600

-- generates 10Khz 50% duty
PWM1CLKCON = 0b00000001 ; HFINTOSC
PWM1CON = 0b11000000
PWM1PH = 800  
PWM1DC = 1600  
PWM1PR = 1600



Rob Hamerling

unread,
Dec 16, 2024, 5:12:11 AM12/16/24
to jallib

Hi Vasili,

The compiler seems to stop the processor when the program ends.  During the forever loop the clkout pin shows a Fosc/4 signal, but when you exit the loop the clkout pin is quiet (and the  the PWM signal stops also!).
Proof: at the end of the assembler code there is 'sleep' statement/loop.

Regards, Rob.



On 16-12-2024 07:46, vsurducan wrote:
Hi Rob, I have understood some things:
1. Indeed the 12F1572_blink_intosc, with pragma target CLKOUTEN ENABLED returns Fosc/4 on RA4 pin only if forever loop end loop exists. If you expect to have that clock without any repetitive main program (comment the forever loop), it will not be there.
It's possible to be a compiler issue, or a normal behavior of the microcontroller, I do not now.


Rob Hamerling

unread,
Dec 16, 2024, 9:49:41 AM12/16/24
to jal...@googlegroups.com

Hi Vasili,

I have no scope on hand. My multimeter (UT61E) has a feature to measure frequency and duty cycle.

With Fosc = 8 MHz it shows 2 MHz on the clkout pin and 5 KHz on the PWM1 pin.
With Fosc = 32 MHz: 8MHz on clkout pin, 20 KHz on PWM1 pin.


Regards, Rob.


On 16-12-2024 07:46, vsurducan wrote:

2. The code below is showing on my scope 10Khz. However I've learned that depends by antialising filter of the scope. 
Can you please take a look on the scope on 20uS time base, on both 8MHz and 32Mhz Clock? I'm curious what you will find.


vsurducan

unread,
Dec 16, 2024, 10:42:49 AM12/16/24
to jal...@googlegroups.com
Yep. This is what I also have now. But only after a hard reset. It does works random  with internal MCLR. I will replace the chip. However, issue is solved, I think. Thx.

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.

Rob CJ

unread,
Dec 21, 2024, 3:52:27 AM12/21/24
to jal...@googlegroups.com
Hi Rob_H,

A late reaction but I was away last week.

About PWM issue #208. This year I worked on this - not remembering that this issue was reported - and added 16-bit PWM up to 12 channels. This is not yet in the current release but it is in the bee-packages.

If you look in the changelog of the bee-package you find this:

peripherals:
 - Update of pwm_pwm1.jal, pwm_pwm2.jal, pwm_pwm3.jal, pwm_pwm4.jal, pwm_pwm5.jal, pwm_pwm6.jal.
   Added 16-bit PWM functionality in addition to the existing 10-bit PWM functionality.
 - Added pwm_pwm7.jal, pwm_pwm8.jal, pwm_pwm9.jal, pwm_pwm10.jal, pwm_pwm11.jal, pwm_pwm12.jal
   Includes 10-bit PWM and 16-bit PWM.
 - Update of pwm_hardware.jal. Added PWM7..PWM12.
 - Update of pwm_common.jal. Added 16-bit PWM functionality and extended the prescaler ranges.
   2-bit prescaler was extended with prescale 64 and 3-bit prescaler supports prescale 1..128.

I think that when a new Jallib release is made - next year - this issue can be closed, agree?

Kind regards,

Rob_J


Van: jal...@googlegroups.com <jal...@googlegroups.com> namens vsurducan <vsur...@gmail.com>
Verzonden: zondag 15 december 2024 16:26
Aan: jal...@googlegroups.com <jal...@googlegroups.com>
Onderwerp: Re: [jallib] Re: pragma target clockouten issue?
 

vsurducan

unread,
Dec 21, 2024, 4:08:21 AM12/21/24
to jal...@googlegroups.com
Hi Rob, just a thought, I'm not asking anything. I recall it were written a lot of pwm library versions. I do not know if the last one allows you to set the pwm frequency, which is important. Finally you can do that from registers, anyway.

Happy holidays!

Rob Hamerling

unread,
Dec 21, 2024, 4:11:24 AM12/21/24
to jallib

Hi Rob_C,

On 21-12-2024 09:52, Rob CJ wrote:
Hi Rob_H,

About PWM issue #208. This year I worked on this - not remembering that this issue was reported - and added 16-bit PWM up to 12 channels. This is not yet in the current release but it is in the bee-packages.


Looks indeed that issue #208 can be closed. Probably #210 too.

But I would not know if these updates satisfy the needs of Vasili with the 12F1572...

Regards, Rob.

vsurducan

unread,
Dec 21, 2024, 5:34:28 AM12/21/24
to jal...@googlegroups.com
Don't worry.  I do not use libraries on critical things. Having a good example in a libray it is ok. Thx.

Regards, Rob.



--
Rob Hamerling, Vianen, NL

--
You received this message because you are subscribed to the Google Groups "jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jallib+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages