PIC16F18326 PMW Timer 2 only available timer
Moderator: Benj
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
PIC16F18326 PMW Timer 2 only available timer
Hi,
Using a PIC16F18326, when selecting a timer to associate with a given PWM channel, timer 2 is the only available timer. Thanks
Zane
Using a PIC16F18326, when selecting a timer to associate with a given PWM channel, timer 2 is the only available timer. Thanks
Zane
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
I was wondering if you have been able to have a look at this problem yet. With only having access to one timer i cannot get separate PWM channels to act with different different parameters.
Thanks in advance.
Zane
I was wondering if you have been able to have a look at this problem yet. With only having access to one timer i cannot get separate PWM channels to act with different different parameters.
Thanks in advance.
Zane
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
Just having a look into this for you now. It's quite awkward because Microchip have changed the values on the 16F18326 family.
Normally 0=T2, 1=T4, 2=T6 and 3=Reserved.
However on your device it's changed so 0/1=T2, 2=T4, 3=T6
Looking in the compiler definitions there is no way to know the correct value. Hmm I might need to think about this one.
Just having a look into this for you now. It's quite awkward because Microchip have changed the values on the 16F18326 family.
Normally 0=T2, 1=T4, 2=T6 and 3=Reserved.
However on your device it's changed so 0/1=T2, 2=T4, 3=T6
Looking in the compiler definitions there is no way to know the correct value. Hmm I might need to think about this one.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
I think I've managed it, have a go and see how you get on.
First copy this to your "Flowcode 7/FCD/PIC" folder.
Next copy this to your "Flowcode 7/Components" folder.
Finally copy this to your "Flowcode 7/CAL/PIC" folder.
Restart Flowcode and fingers crossed you should now be able to select the three timers and it should work.
Let us know how you get on.
I think I've managed it, have a go and see how you get on.
First copy this to your "Flowcode 7/FCD/PIC" folder.
Next copy this to your "Flowcode 7/Components" folder.
Finally copy this to your "Flowcode 7/CAL/PIC" folder.
Restart Flowcode and fingers crossed you should now be able to select the three timers and it should work.
Let us know how you get on.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
Thanks for your efforts here. A job well done. I have tried these in software and it all seems to work fine
. I went through and tried to test it on hardware but was unsuccessful. Using a program that i know works with a given device (PIC12F1840) the PICKIT 3 and Flowcode can connect. If using the same program and i change the device to a PIC16F18623 i get the following message.
I'm not overly sure why this might be happening. Do you have any ideas?
Thanks
Zane
Thanks for your efforts here. A job well done. I have tried these in software and it all seems to work fine

Thanks
Zane
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
The device is very new and may not be supported with the old PICkit 3 programming tool (PK3CMD). I would recommend you use the new MPLAB IPE software that comes with MPLABX.
You can run this in GUI mode or you can use via a command line with Flowcode. Details on how to set this up here.
https://www.matrixtsl.com/wikiv7/index. ... _.28NEW.29
Warning once you use the IPE it will flash your PICkit is a way that it will no longer work with the PK3CMD software. To restore the older firmware there is an option in MPLAB 8 which will allow you to use PK3CMD again. I use the IPE software for pretty much everything now as it's very good.
The device is very new and may not be supported with the old PICkit 3 programming tool (PK3CMD). I would recommend you use the new MPLAB IPE software that comes with MPLABX.
You can run this in GUI mode or you can use via a command line with Flowcode. Details on how to set this up here.
https://www.matrixtsl.com/wikiv7/index. ... _.28NEW.29
Warning once you use the IPE it will flash your PICkit is a way that it will no longer work with the PK3CMD software. To restore the older firmware there is an option in MPLAB 8 which will allow you to use PK3CMD again. I use the IPE software for pretty much everything now as it's very good.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
Thanks for the advice with the MPLAB IPE software. I have set it up as you have advised and can now program using this software tool.
When programming a chip i get the message below saying an invalid device is connected, however it seems to go through and program the target device without a problem. I am not sure how much of an issue this is?
I have have created a small flowchart An interrupt is triggered by a given timer. There is an output A5 that is toggled periodically when the interrupt routine is processed. In the main loop there is also a an output A4 that is also toggled every program cycle.
What i have found using the PIC16F18326 when using timers T0, T1 and T2 the interrupt routine is processed. Using timers T3,T4,T5 and T6 the interrupt routine is not processed. Regardless of the timer used the ouput A4 in the main loop will always toggle every program cycle.
I have also found that even though timer 2 works in the above example. When it is associated with a PWM channel, that channels output does not function.
I have found in the data sheet for this chip in section 14, the peripheral disable registers and wonder if they could be a source of problems?
Thanks for your help
Zane
Thanks for the advice with the MPLAB IPE software. I have set it up as you have advised and can now program using this software tool.

When programming a chip i get the message below saying an invalid device is connected, however it seems to go through and program the target device without a problem. I am not sure how much of an issue this is?
I have have created a small flowchart An interrupt is triggered by a given timer. There is an output A5 that is toggled periodically when the interrupt routine is processed. In the main loop there is also a an output A4 that is also toggled every program cycle.
What i have found using the PIC16F18326 when using timers T0, T1 and T2 the interrupt routine is processed. Using timers T3,T4,T5 and T6 the interrupt routine is not processed. Regardless of the timer used the ouput A4 in the main loop will always toggle every program cycle.
I have also found that even though timer 2 works in the above example. When it is associated with a PWM channel, that channels output does not function.
I have found in the data sheet for this chip in section 14, the peripheral disable registers and wonder if they could be a source of problems?
Thanks for your help
Zane
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
I'm just having another look through the definition file I sent you and comparing with the datasheet, t4 and t6 should be identical to t2, t3 and t5 should be identical to t1. So far I haven't found anything that looks like it would be causing issues. When changing between timers were you going into the timer properties to configure the clock source etc. Just wondering if the higher timers are defaulting to being clocked from external pins?
I'm just having another look through the definition file I sent you and comparing with the datasheet, t4 and t6 should be identical to t2, t3 and t5 should be identical to t1. So far I haven't found anything that looks like it would be causing issues. When changing between timers were you going into the timer properties to configure the clock source etc. Just wondering if the higher timers are defaulting to being clocked from external pins?
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
Looking at the flowchart posted in the post above, i have set the timer properties in the interrupt icon for the tests that i have done.
Thanks for checking this out.
Cheers
Zane
Looking at the flowchart posted in the post above, i have set the timer properties in the interrupt icon for the tests that i have done.
With timers 2, 4 and 6 there are no options to select the clock source. With timers 0, 1, 3 and 5 there is the ability to select the source of the clock. In each instance for these timers i have selected the internal clock source within the properties section in the interrupt icon. As mentioned above the only timers that can trigger the interrupt routine at the moment are timers 0, 1 and 2.When changing between timers were you going into the timer properties to configure the clock source etc.
With timer 2 how i mentioned, i have selected that as the timer used to trigger the interrupt routine. When this is done the interrupt is triggered and the output that is toggled from within the routine is active. However as soon as timer 2 is associated with a PWM channel, that channel is inactive. The same goes for timers 4 and 6. (With timer 2 associated with a PWM channel another timer was associated with triggering the interrupt routine).I also mentioned above about the peripheral disable registers possibly being an issue but it looks like they are all enabled by default.Just wondering if the higher timers are defaulting to being clocked from external pins?
Thanks for checking this out.
Cheers
Zane
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi
I see your point there is a chance I could have been supplied with the wrong chip. I will double check that tomorrow. I still have the issue however with timer 2 and not working with the PWM channel. Thanks for your help.
Cheers
I see your point there is a chance I could have been supplied with the wrong chip. I will double check that tomorrow. I still have the issue however with timer 2 and not working with the PWM channel. Thanks for your help.
Cheers
- Attachments
-
- Capture.JPG (13.4 KiB) Viewed 26993 times
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Thanks Kenrix for spotting my rookie mistake, what i thought i ordered and what i got...two different things
time for my next set of glasses.
I have changed the device to a PIC16f18323. When trying to drive the PWM channel from timer 2 it will not work. I have used the same small program using a PIC16F88 and the PWM output works.
Thanks
Zane


I have changed the device to a PIC16f18323. When trying to drive the PWM channel from timer 2 it will not work. I have used the same small program using a PIC16F88 and the PWM output works.
Thanks
Zane
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
Have you had a chance to look into the problem with the PIC16F18323 with the PWM not working when using timer 2 to drive the channel?
Cheers
Zane
Have you had a chance to look into the problem with the PIC16F18323 with the PWM not working when using timer 2 to drive the channel?
Cheers
Zane
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
I've had a go, here are some files you can try.
I've had a go, here are some files you can try.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
Thanks, i have tried with these file updates and it works a treat.
How the .FCDX file required updating to allow the PWM output to work on the PIC16F18323, is the same mod required for the PIC16F18326's .FCDX file as well? If so are you able to post the mod for that file as well.
Thanks
Zane
Thanks, i have tried with these file updates and it works a treat.

How the .FCDX file required updating to allow the PWM output to work on the PIC16F18323, is the same mod required for the PIC16F18326's .FCDX file as well? If so are you able to post the mod for that file as well.
Thanks
Zane
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
Thanks for letting us know, glad it's working correctly now.
I've now included all these updates and more here to make it easier to ensure you're fully up to date.
viewtopic.php?f=63&t=19743
Thanks for letting us know, glad it's working correctly now.
I've now included all these updates and more here to make it easier to ensure you're fully up to date.
viewtopic.php?f=63&t=19743
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben
I have ordered some PIC16F18326's. When they arrive i will try with those too and let you know how we get on. I am sure they will work a treat. Once again thanks for your help.
Cheers
Zane
I have ordered some PIC16F18326's. When they arrive i will try with those too and let you know how we get on. I am sure they will work a treat. Once again thanks for your help.

Cheers
Zane
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
I have downloaded the latest updates. I can get both PWM channels to work. However it looks like when using T4 or T6 to drive a given channel it looks like T4 and T6 are getting their values from T2. When using T2 all the timing values seem correct.
Thanks
Zane
I have downloaded the latest updates. I can get both PWM channels to work. However it looks like when using T4 or T6 to drive a given channel it looks like T4 and T6 are getting their values from T2. When using T2 all the timing values seem correct.
Thanks
Zane
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
I was wondering if you have had a chance to follow this up. I have also found that when using T2, T4 or T6 to drive an interrupt they all work at the given intervals set and when T4 and T6 are used with a PWM channel they experience the problems mentioned in the last post.
Thanks
Zane
I was wondering if you have had a chance to follow this up. I have also found that when using T2, T4 or T6 to drive an interrupt they all work at the given intervals set and when T4 and T6 are used with a PWM channel they experience the problems mentioned in the last post.
Thanks
Zane
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
Not yet but I'll get back onto it for you this week, sorry for the delay it's been a bit hectic with the launch of v8.
Not yet but I'll get back onto it for you this week, sorry for the delay it's been a bit hectic with the launch of v8.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
Right I've managed to spend a bit more time on this now and can't seem to find any problems in the code, though there could be problems lurking.
Can you explain a bit further what problem you've noticed and ways to try and replicate the problem.
Right I've managed to spend a bit more time on this now and can't seem to find any problems in the code, though there could be problems lurking.
Can you explain a bit further what problem you've noticed and ways to try and replicate the problem.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 199
- Joined: Thu Sep 10, 2009 10:57 pm
- Location: New Zealand
- Has thanked: 93 times
- Been thanked: 76 times
Re: PIC16F18326 PMW Timer 2 only available timer
Hi Ben,
Thanks for looking at this for me. I have attached a small program where the two PWM channels are used. Channel 1 has timer 2 assigned to it. The values used for the period and the duty cycle work as expected.
Channel 2 has timer 4 assigned to it. Any changes to the period are not reflected in the output waveform. However when the period for channel 1 - timer 2 are adjusted they affect the period of channel 2. The duty cycle of channel 2 works ok. I have tried using timer 6 in place of timer 4 and it also seems to have its period referenced to timer 2.
Timer 6 in the program is used to drive an interrupt routine and it is set to activate every 1ms. From within the interrupt routine an output is set to toggle on and off every second, this works correctly. So it looks like the timing issue so far seems isolated to the PWM function of the chip.
Another output is toggled in the main routine every 1mS, driven by FC delays. The timing of this is also correct.
Also as a side note i have noticed when selecting what channel is to be used for the PWM, the drop down menu has four available channels. This chip has only two.
I hope this is of some help.
Thanks
Zane
Theoretical outputs for channel 1 and channel2.
Actual outputs from PIC.
Scope Channel 1 = PWM channel 1
Scope Channel 2 = PWM channel 2
Thanks for looking at this for me. I have attached a small program where the two PWM channels are used. Channel 1 has timer 2 assigned to it. The values used for the period and the duty cycle work as expected.
Channel 2 has timer 4 assigned to it. Any changes to the period are not reflected in the output waveform. However when the period for channel 1 - timer 2 are adjusted they affect the period of channel 2. The duty cycle of channel 2 works ok. I have tried using timer 6 in place of timer 4 and it also seems to have its period referenced to timer 2.
Timer 6 in the program is used to drive an interrupt routine and it is set to activate every 1ms. From within the interrupt routine an output is set to toggle on and off every second, this works correctly. So it looks like the timing issue so far seems isolated to the PWM function of the chip.
Another output is toggled in the main routine every 1mS, driven by FC delays. The timing of this is also correct.
Also as a side note i have noticed when selecting what channel is to be used for the PWM, the drop down menu has four available channels. This chip has only two.
I hope this is of some help.
Thanks
Zane
Theoretical outputs for channel 1 and channel2.
Actual outputs from PIC.
Scope Channel 1 = PWM channel 1
Scope Channel 2 = PWM channel 2
- Attachments
-
- Flowcode1.fcfx
- (14.11 KiB) Downloaded 376 times
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
Many thanks I have now managed to replicate the issue and am now looking into it for you.
Many thanks I have now managed to replicate the issue and am now looking into it for you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
- 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: PIC16F18326 PMW Timer 2 only available timer
Hi Zane,
Finally managed to get to the bottom of the problem for you. On the device you're using the PWM timer selection register is defined slightly differently in the compiler definitions and so the selection register code was being ignored.
Please try the attached file and it should solve the problem for you.
Finally managed to get to the bottom of the problem for you. On the device you're using the PWM timer selection register is defined slightly differently in the compiler definitions and so the selection register code was being ignored.
Please try the attached file and it should solve the problem for you.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel