PWM1 and 16F1827

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

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:

PWM1 and 16F1827

Post by Jan Lichtenbelt »

The microcontroller 16F1827 has the possibility of 4 PWM's. Flowcode can use the first two. PWM2 works correctly, but PWM1 fails when used with Flowcode. This is due to the fact that the wrong output port is programmed. The default output port for PWM1 is B3 and for PWM2 is B6. In the assembler program it can be seen that B0 instead of B3 is used.
This problem can easily be overcome in Flowcode by puting zero on B3 as output directly after enabling PWM1 (setting trisb to the correct value).

Succes

Jan Lichtenbelt
---------------
; { FCD_PWM0_Enable ; function begin
MOVLW 0xFF
MOVWF gbl_pr2
MOVLW 0x06
MOVWF gbl_t2con
DECF FCD_PWM0_E_00047_arg_nIdx, W
BTFSS STATUS,Z
GOTO label4
MOVLW 0x0C
MOVLB 0x05
MOVWF gbl_ccp1con
MOVLB 0x01
BCF gbl_trisb,0
label4
MOVLB 0x00
MOVF FCD_PWM0_E_00047_arg_nIdx, W
XORLW 0x02
BTFSS STATUS,Z
RETURN
MOVLW 0x0C
MOVLB 0x05
MOVWF gbl_ccp2con
MOVLB 0x01
BCF gbl_trisb,6
RETURN
; } FCD_PWM0_Enable function end

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: PWM1 and 16F1827

Post by Benj »

Hello Jan,

Thanks for the info. Here are a couple of fixed FCD files that should resolve the problem for you.

Also all PWM channels have been added to the v5 FCD file so hopefully we should be able to support all PWM channels rather then just 2.
Attachments
16F1827.fcd
(10.15 KiB) Downloaded 298 times
16F1826.fcd
(10.15 KiB) Downloaded 287 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: PWM1 and 16F1827

Post by Jan Lichtenbelt »

Dear Ben,

At the end, I will use the smallest PIC as possible. The equivalent 14 pins is the 16F1825. Is there also an update of the FDC file for this microcontroller?

Kind regards

Jan

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: PWM1 and 16F1827

Post by Benj »

Hello Jan,

I think the 16F1825 device is ok but I will have a quick check and make sure for you.

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: PWM1 and 16F1827

Post by Jan Lichtenbelt »

Dear Ben,

Please be informed that the TRM1 with transition on T1CKI pin does not work correctly with 16F1825.
st_bit(t1con,TMR1CS); gives an error (TMR1CS unknow identifier).

TMR1CS<1:0> is bit<7:6> of T1CON register and should become 10 in this mode.

I do not use it now, but a suggestion is to improve the FCD file for the Flowcode V5.

Kind regards

Jan Lichtenbelt

Dmitry Maximenko
Flowcode V4 User
Posts: 36
Joined: Mon Sep 26, 2011 10:26 pm
Has thanked: 9 times
Been thanked: 2 times
Contact:

Re: PWM1 and 16F1827

Post by Dmitry Maximenko »

Benj
After updating of 16f1827.fcd my PWM stopped to work!
What happens? :-)
Please advice
Thank 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: PWM1 and 16F1827

Post by Benj »

After updating of 16f1827.fcd my PWM stopped to work!
Check you are not using the alternate pin in either the PWM properties or the chip config settings.

Dmitry Maximenko
Flowcode V4 User
Posts: 36
Joined: Mon Sep 26, 2011 10:26 pm
Has thanked: 9 times
Been thanked: 2 times
Contact:

Re: PWM1 and 16F1827

Post by Dmitry Maximenko »

Hi Benj!
When I had old FCD file it worked when I had option "alternate pin" activated, not without it.
OK,now, when I changed to new FCD it seems to work if I change "alternate pin" to off.
Should it work that way?

Benj, what do you mean by "or the chip config settings"?

Thank you!
Best Regards
Dmitry

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: PWM1 and 16F1827

Post by Benj »

Hello,

To use the alternate PWM pin you have to enable the setting in the PWM properties window and enable the setting in the Chip -> Configure -> Expert Settings window.

Post Reply