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.

On Sun, Dec 15, 2024 at 10:12 PM Rob Hamerling <[email protected]>
wrote:

>
> 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
>
>
>
> On 15-12-2024 16:14, vsurducan wrote:
>
> 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
>
> On Sun, Dec 15, 2024 at 4:41 PM Rob Hamerling <[email protected]>
> wrote:
>
>>
>> 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..
>>
>> On 14-12-2024 12:15, vsurducan wrote:
>>
>> 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
>> --
>> 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 [email protected].
>> To view this discussion visit
>> https://groups.google.com/d/msgid/jallib/CAM%2Bj4qskr5urcQxa_Ok3gHTeq4nMBAtz%2BkmziB4kBf1HBuHCJg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/jallib/CAM%2Bj4qskr5urcQxa_Ok3gHTeq4nMBAtz%2BkmziB4kBf1HBuHCJg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>>
>> --
>> *Rob H*amerling, 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 [email protected].
>> To view this discussion visit
>> https://groups.google.com/d/msgid/jallib/1c978896-3436-41c8-be39-b2d1bd05dc3b%40gmail.com
>> <https://groups.google.com/d/msgid/jallib/1c978896-3436-41c8-be39-b2d1bd05dc3b%40gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> 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 [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/jallib/CAM%2Bj4qsF4Ew0bxJG1h_CkC4cHSxyS%3DTEGtHeVtwFzm4h%2B53y5Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/jallib/CAM%2Bj4qsF4Ew0bxJG1h_CkC4cHSxyS%3DTEGtHeVtwFzm4h%2B53y5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
>
> --
> *Rob H*amerling, 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 [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/jallib/7f22d2e1-7fbb-4e45-b68f-5ef134aa285f%40gmail.com
> <https://groups.google.com/d/msgid/jallib/7f22d2e1-7fbb-4e45-b68f-5ef134aa285f%40gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/jallib/CAM%2Bj4qs-_s5qwDYuck_v-Fx%2BWX-LoT0yi4%2BV6yUuCwyKwLptBw%40mail.gmail.com.

Reply via email to