Page 1 of 1

PWM 18F27K40

Posted: Mon Jul 29, 2019 3:57 pm
by medelec35
Clock frequency confirmed by 10Hz test as being 48MHz.
the delay is exactly 100ms,
Required PWM frequency = 10KHz
PWM properties:
PWM issue.png
(50.45 KiB) Downloaded 2752 times
Measured PWM frequency = 375Hz

Re: PWM 18F27K40

Posted: Tue Jul 30, 2019 4:45 pm
by Benj
Thanks for letting u sknow Martin,

Been EMC testing all morning and what with the heat I can't focus on this at the moment. I started and failed :wink:

I'll try and make this a priority to solve for you. Probably something to do with assuming 8/10 bit PWM but actually it's 16-bit.

Re: PWM 18F27K40

Posted: Tue Jul 30, 2019 4:49 pm
by medelec35
Benj wrote:what with the heat I can't focus on this at the moment
I can understand that, at least rain has help to cool things down?
Benj wrote:'ll try and make this a priority to solve for you.
That's brilliant!
Thank you Ben.

Re: PWM 18F27K40

Posted: Mon Aug 05, 2019 9:20 am
by medelec35
Hi Ben,
Did you get a chance to look into PWM?

Re: PWM 18F27K40

Posted: Tue Aug 06, 2019 11:42 am
by Benj
Hi Martin,

I've looked a few times, this family seems to be breaking rules all over the place. I'll keep on with it :D

Re: PWM 18F27K40

Posted: Wed Aug 07, 2019 9:32 am
by medelec35
Hi Ben,
Just noticed something after starting a new test Flowchart.
The PWM does not work at all until I added a timer2 interrupt!
After adding the interrupt, PWM will then run at the wrong frequency.
So it's getting the values from timer2 interrupt.
How strange.:?

Edit: Changed timer 2 Prescaler rate to 1 and the PWM went from 375Hz to 47.25KHz
This may help to shed some light on it?
PWM is set for timer 4

Re: PWM 18F27K40

Posted: Wed Aug 07, 2019 3:28 pm
by medelec35
In addition to the above post.
PWM will only work if select PWM timer for Timer 4 (Tried with timers 2 & 6 which does not work).
The PWM will work at the correct frequency if Timer2 interrupt Prescale Rate is set to the required PWM Prescale.
Timer 2 interrupt Rollover Value is set to the required PWM period.
The timer 2 interrupt can be enabled, then disabled straight away.
PWM will still function correctly.
Note:
If timer2 Postscaler Rate is left on 1:1 then the Interrupt Frequency displayed will be the PWM frequency.
Hope this helps anyone with PIC18FXXK40 who requires PWM

Re: PWM 18F27K40

Posted: Tue Sep 10, 2019 8:23 am
by medelec35
Hi Ben,
Was wondering if this has been fixed?

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 9:56 am
by Benj
Hi Martin,

I've had another look into the problem this morning and pushed a change to the device definition files which hopefully solves the problem.

Thanks for chasing this one up.

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 11:45 am
by medelec35
Hi Ben,
Sorry, still the same after updating with new fcdx file.
PWM does not work until timer2 interrupt set up as described in my above post.

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 12:20 pm
by Benj
Hi Martin,

Wow thanks for getting back so fast. I beleive I have now found and fixed the problem for you.

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 1:07 pm
by medelec35
Hi Ben,
Benj wrote:Wow thanks for getting back so fast.
You're welcome.
I'm afraid the latest version cases the following error:
Build date: Nov 15 2017
Part Support Version: 1.45
Copyright (C) 2017 Microchip Technology Inc.
License type: Node Configuration

MX_PWM_ALTTIMER: 748: (1500) invalid token in #if expression
(908) exit status = 1
(908) exit status = 1

Error returned from [xc8.exe]

C:\Program Files (x86)\Flowcode\Compilers\pic\batch\pic_xc8_comp.bat reported error code 1

Autoclose turned off


FINISHED

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 3:06 pm
by Benj
Thanks Martin,

Third time's the charm (hopefully) :D

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 4:02 pm
by medelec35
Hi Ben,
Tried with timers 2,4 & 6.
All working now.
Thank you.

Re: PWM 18F27K40

Posted: Wed Sep 11, 2019 4:10 pm
by Benj
Woohoo, :D :D :D

Excellent, sorry this was so long in getting to you and really happy this is working correctly now.

Thanks for bearing with and letting me know.