PWM PIC18F47K40

A forums to allow bugs and problems with Flowcode v7 to be reported and resolved.

Moderator: Benj

Post Reply
User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

PWM PIC18F47K40

Post by jollybv »

Hi Guys

I am trying to get the PWM to work it works in the test program below in simulation but will not work on the hardware any ideas
TestPWM.fcfx
(9.06 KiB) Downloaded 209 times

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 PIC18F47K40

Post by medelec35 »

Hi Brian,
First I would suggest to make sure FC7 is fully up to-date, if not already done so.
You can update will the files from here.
I had an issue with PWM on 27K40 running FC8.
I posted a work around here as it could also apply to FC7 as well with your target device?
Of course, don't forget to make sure the one second flasher works.
I have moved topic to a more suitable place than user components.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Martin

Thanks, I have tried all of the above suggestions but still can't get it to work, 1-second flasher working on RB0 So Pick working correctly, Have updated flowcode tried using Timer 4 still noting so not sure where to go from here.

howard123
Posts: 75
Joined: Thu May 24, 2012 1:15 pm
Location: Cape Town
Has thanked: 30 times
Been thanked: 28 times
Contact:

Re: PWM PIC18F47K40

Post by howard123 »

Hi Brian
I have no idea if this is relevant but I noticed that the watchdog is on. Also could you try TMR2 and TMR4 with the PWM disabled. Set each timer to interrupt at a defined frequency and test on a pin that the frequency is correct.
Howard

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Howard

Thanks for the reply I have turned off the watchdog timer but that does not help. I'm not sure how to set the timer 2 and 4 to show me a predetermined frequancy could you please explain

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 PIC18F47K40

Post by Benj »

Maybe try enabling the associated timer interrupt using an interrupt icon. The interrupt macro could just be a blank macro. That might help get things moving and would help us to know where in the code to look for the problem.

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Ben

I have tried to do that without any luck, but if I enable the disabled code in the TimerInt macro in the example program below then I get a frequency of 492Hz, this PWM refuses to work on any of the timers.
TestPWM.fcfx
(10.79 KiB) Downloaded 209 times

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 PIC18F47K40

Post by medelec35 »

jollybv wrote:then I get a frequency of 492Hz,
Did you set the timer 2 prescale and rollover as explained in the link I posted?
I had the same issue as you.
I could then at least control the PWM frequency.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Martin

I'm a bit lost now

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.

I have set the rollover time of the TMR2 Interrupt to 255 and the prescale Rate to 64 it is enabled then strait away disabled.
I have also set the PWM Period Overflow to 255 and the Prescale To 64

I'm still not getting anything please see in the test program if I'm understanding you correctly.
TestPWM.fcfx
(11.67 KiB) Downloaded 197 times

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 PIC18F47K40

Post by medelec35 »

I have modified your flowchart so hopefully PWM will run at 4KHz
Attachments
TestPWM.fcfx
(11.61 KiB) Downloaded 199 times
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Thanks, Martin but ist still does not work think there must be something wrong with the PWM component

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 PIC18F47K40

Post by medelec35 »

Hi Brian,
No problem.
jollybv wrote:think there must be something wrong with the PWM component
Yes, seems like it.
Was just trying to get it kick stated as will help Ben to fix it.
That's what happened with 18F27K40
Have you tried changing mapping for a different pin?
Also, can you set the duty to 15 rather than a variable.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi yes have remapped with no success
and did set the duty cycle to 15 but alas no luck,

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Guys

As the PWM Component is not working and I'm waiting for Ben to have a look at it, does anyone know how I can make a PWM using a timer interrupt?

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 PIC18F47K40

Post by medelec35 »

Hi Brian,
What PWM frequency is required?
With bit bang, best to have as lower frequency as possible.
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 PIC18F47K40

Post by medelec35 »

I have had a go at fixing the PWM.
I have noticed form looking at the file I2C will require fixing as well.
Unable to verify if working, as not got PIC18F47K40 to test with.
Therefore, may or may nor work?
If 64 bit windows:
Can you place the attached file in C:\Program Files (x86)\Flowcode 7\FCD\PIC\
Or if 32bit windows:
C:\Program Files\Flowcode 7\FCD\PIC\

Best to keep a copy of the original file.
Attachments
18F47K40.fcdx
(43.6 KiB) Downloaded 137 times
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Martin

Sorry for responding so late been out the whole day, Thanks for your help I will give it a try and let you know

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Martin

I have given it a try and it is now working Thanks so much :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 PIC18F47K40

Post by medelec35 »

jollybv wrote:I have given it a try and it is now working Thanks so much
,
Glad its working for you. :D
Thanks for the update.
At least you can carry on until an official fix from Matrix.
Ben has been on Holiday, so no doubt will have lots of catching up to do.
Martin

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Guys

Im not sure if this is still part of the problem with the A/D component not working correctly. On A0 I have a voltage of 0.182 which im trying to display on the LCD screen. I'm using (get analog voltage) and then converting it to a string then printing to screen but what it displays is 0.078 and sometimes flashes 0.182 it looks like it is not reading the correct voltage every time not sure if its me that is doing somthing wrong or there is a bug still in the PIC18F47K40.

I would like to get this resolved as soon as posible as i need to test this over the weekend
Pic1.jpg
Pic1.jpg (128.62 KiB) Viewed 8892 times
PWM_With_Temp_INT_Setup.fcfx
(109.96 KiB) Downloaded 136 times

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 PIC18F47K40

Post by Benj »

Maybe try a slower conversion speed and see if that helps, might be a touch too fast at the current clock speed, also do you have any noise present on the ADC pin, Maybe a decoupling capacitor to ground or a full R/C filter to help some noise rejection?

User avatar
jollybv
Flowcode v5 User
Posts: 374
Joined: Thu Feb 12, 2009 5:20 am
Location: Cape Town
Has thanked: 81 times
Been thanked: 25 times
Contact:

Re: PWM PIC18F47K40

Post by jollybv »

Hi Ben

Thanks for your reply that seems to have solved the problem I set it to Focs / 128, now I need to get the PID side of things working (tried buying a PID controller but with this Vuires cant get much here in SA)

Post Reply