PWM alternative pin is not working 12F1840

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

I use the 12F1840 with PWM stelection on 2 pins. In Flowcode 5 it works fine, but it fails in Flowcode 6. I use the alternative pin selection (CCP1SEL bit of the apfcon register) by means apfcon =0x00; and apfcon=0x01; But the alternative pin A5 fails.

What to do?

Kind regrads

Jan Lichtenbelt
Attachments
Test1.fcfx
(5.31 KiB) Downloaded 212 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

The solution was simple. The output pins has to be set at zero after changing the alternative pins. See improved flowocode.

Kind regards

Jan Lichtenbelt
Attachments
Test1_V2.fcfx
(5.5 KiB) Downloaded 231 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 alternative pin is not working 12F1840

Post by Benj »

Hi Jan,

Aha thanks for letting us know about this. I have now added the alt pin to the FCD for this device and also added the appropriate C calls so it will automatically work out the box.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

Hi Ben,

I changed the FCD file also. But can you tell me what to change in de C-code calls? ( I still have troubles )

Kind regards

Jan Lichtenbelt

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 alternative pin is not working 12F1840

Post by Benj »

Hi Jan,

I have made changes to the FCD, The PWM CAL Code and the PWM CAL Component so there is quite a lot that has changed. Basically allowing me to specify the correct pin and even the afpcon register and it's bit position so the C CAL code will set the right pin to be an output and assign the functionality to the correct pin. All these changes will be included in the next release of Flowcode.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

I have still to work with this version. The Test-V2 flowcode as is works correct . But put I this program as part of an other Flowcode 6 program, it fails agian on the alternative port.
I first tried to read the asm file but fail to find difference. Then I set just before starting the PWM, all relevant registers to 0x00, but without improvemnts

Does someone have suggestions to get the PWM with alternative pin as part of an other progam?

Kind regards

Jan Lichtenbelt

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

The error starts after a Timer1 intterupt enable statement. As far as I see, Timer1 may not influence the PWM (with Timer2) working.

What happens??

Kind regards

Jan Lichtenbelt

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

It all sound difficult. Therefore I made very easy Flowcodes to show the problem.

Please find to Flowcode both with the same intension. PWM during 5 seconds on one pin and 5 seconds on the alternative pin. In both Flowcodes it works correct if the Timer1 is not used. However, if one uses the timer1 before the PWM the alternative pin does not work with 12F1840 microchip, while the 16F1939 works correctly. I compared both assembler files and found only excepted differences (different pins A2-A5 / E0-B5 and CCP1 / CCP3 for respectively 12F1840/16F1939).

Who can help???

Kind regards

JAn Lichtenbelt
Attachments
Test_PWM_16F1939.fcfx
(7.65 KiB) Downloaded 200 times
Test_PWM_12F1840.fcfx
(7.71 KiB) Downloaded 213 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

It took a lot of puzzling, but I found a solution.
Using the Timer1, the Timer1 will be enabled with setting the Timer1 control register (T1CON) and enabling the Timer1 Overflow Interrupt bit (TMR1IE) of the Peripheral Interrupt Register (PEI1). Stopping Timer1 is done by ONLY disabling this last bit TMR1IE and leaving the T1CON register as is.
In this case the alternate pin configuration (apfcon) with the PWM in this 12F1840 microchip does NOT work correctly.

I found:
1) Using Timer0 or Timer2 before the PWM does not disturb the alternate pin configuration apfcon of the PWM.
2) Setting the T1CON with Timer1 is the same principal as e.g. setting the T2CON for the Timer2.
3) in both case no other registers are used
4) Timer2 is disabled also only by resetting the TMR2IE bit of PIE1.
So far it is very unclear why Timer1 does have influence on the working of the alternative pin of PWM?

5) Now I cleared additional the Timer1 ON bit of the Timer1 directly AFTER disabling the Timer1 interrupt with:
cr_bit(t1con,TMR1ON);

And now the alternative pin (apfcon) of PWM works correctly!!!!!

Kind regards

Jan Lichtenbelt


PS: Set boolean A true or false in the Flowcode attached and see the difference.
Attachments
Test_PWM_12F1840_V2.fcfx
(8.4 KiB) Downloaded 199 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

Continue the story:

In an other application resetting of the TMR1ON bit is not enough. Now it was necessary to reset the complete T1CON register with:
t1con=0x00;

I hope this is the last reply.

Kind regrads

Jan Lichtenbelt

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

The alternative PWM pin is still not working correctly under Flowcode 6.0.7. after Timer1 has been used.

Ben can you take action to find a solution for this problem? I would be very happy.

Kind regrads

Jan Lichtenbelt

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 alternative pin is not working 12F1840

Post by Benj »

Hello Jan,

Please can you try the attached FCD and see if this solves the problem completely for you.
Attachments
12F1840.fcdx
(17.07 KiB) Downloaded 178 times

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

Hi Ben,

Thanks for helping. But the alternative PWM pin selection fails still after Timer1 has been used (enabled and disabled).
I hope you have more ideas for an improvement.


Kind regards

Jan Lichtenbelt

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 alternative pin is not working 12F1840

Post by Benj »

Hi Jan,

I put the cr_bit(t1con,TMR1ON); command into the interrupt disable so it should be doing this correctly now.

Did you close and restart Flowcode after updating the file?

You can check by looking at the C code for the timer 1 disable as part of the main function.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: PWM alternative pin is not working 12F1840

Post by Jan Lichtenbelt »

Hi Ben

Later on I found that resetting the cr_bit(t1con,TMR1ON) does not solve the problem. Then I set the whole t1con regsiter to 0x00 which gave some improvement, but not in all cases.

But in principal the contents of the t1con register should not have any influence on the alternative PWM pin selection with the apfcon register. Looking for other then PWM registers can help in some application, but will never a principal solution. It is better to look to the source of the problem, if possible.

I hope you have ideas.

With kind regards

Jan Lichtenbelt

Post Reply