PWM 18F27K40

Moderator: Benj

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

PWM 18F27K40

Post 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
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM 18F27K40

Post 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post 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.
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post by medelec35 »

Hi Ben,
Did you get a chance to look into PWM?
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM 18F27K40

Post 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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post 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
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post 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
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post by medelec35 »

Hi Ben,
Was wondering if this has been fixed?
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM 18F27K40

Post 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post 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.
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM 18F27K40

Post by Benj »

Hi Martin,

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

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post 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
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM 18F27K40

Post by Benj »

Thanks Martin,

Third time's the charm (hopefully) :D

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: PWM 18F27K40

Post by medelec35 »

Hi Ben,
Tried with timers 2,4 & 6.
All working now.
Thank you.
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: PWM 18F27K40

Post 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.

Post Reply