PIC16F18326 PMW Timer 2 only available timer

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

Moderator: Benj

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
Contact:

PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

Hi,

Using a PIC16F18326, when selecting a timer to associate with a given PWM channel, timer 2 is the only available timer.
Capture.JPG
Capture.JPG (13.3 KiB) Viewed 17764 times
Thanks

Zane

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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.

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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.
16F18326.fcdx
(30.27 KiB) Downloaded 277 times
Next copy this to your "Flowcode 7/Components" folder.
cal_pwm.fcpx
(9.85 KiB) Downloaded 263 times
Finally copy this to your "Flowcode 7/CAL/PIC" folder.
PIC_CAL_PWM.c
(28.39 KiB) Downloaded 275 times
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.

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

Hi Ben,

Thanks for your efforts here. A job well done. I have tried these in software and it all seems to work fine :D . 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.
Capture.JPG
Capture.JPG (18.47 KiB) Viewed 17700 times
I'm not overly sure why this might be happening. Do you have any ideas?

Thanks

Zane

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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.

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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. :D

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?
Capture.JPG
Capture.JPG (27.57 KiB) Viewed 17679 times
I have have created a small flowchart
Flowcode4.fcfx
(9.33 KiB) Downloaded 271 times
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

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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?

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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.
When changing between timers were you going into the timer properties to configure the clock source etc.
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.
Just wondering if the higher timers are defaulting to being clocked from external pins?
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.

Thanks for checking this out.

Cheers

Zane

Kenrix2
Flowcode v5 User
Posts: 211
Joined: Tue Feb 19, 2013 9:51 pm
Has thanked: 72 times
Been thanked: 177 times
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Kenrix2 »

From the Device ID it looks like your using a 323 instead of the 326.

Timers 4 and 6 do not exist.

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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
Attachments
Capture.JPG
Capture.JPG (13.4 KiB) Viewed 17591 times

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

Thanks Kenrix for spotting my rookie mistake, what i thought i ordered and what i got...two different things :oops: time for my next set of glasses. :lol:

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

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

Hi Zane,

I've had a go, here are some files you can try.
16F18323.fcdx
(21.53 KiB) Downloaded 170 times
PIC_CAL_PWM.c
(31.68 KiB) Downloaded 190 times

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

Hi Ben,

Thanks, i have tried with these file updates and it works a treat. :D

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

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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. :D

Cheers

Zane

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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.

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

Hi Ben,

How are you going with this, have you managed to find any time to look at this.

Thanks

Zane

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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.

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
Contact:

Re: PIC16F18326 PMW Timer 2 only available timer

Post by Zane »

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
2.jpg
2.jpg (148.15 KiB) Viewed 16966 times
Theoretical outputs for channel 1 and channel2.
1.jpg
1.jpg (133.06 KiB) Viewed 16966 times
Actual outputs from PIC.
Scope Channel 1 = PWM channel 1
Scope Channel 2 = PWM channel 2
Attachments
Flowcode1.fcfx
(14.11 KiB) Downloaded 159 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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

Hi Zane,

Many thanks I have now managed to replicate the issue and am now looking into it for you.

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: PIC16F18326 PMW Timer 2 only available timer

Post by Benj »

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.
PIC_CAL_PWM.c
(31.8 KiB) Downloaded 164 times

Post Reply