PIC16F1508 Timer 2 and PWM Component Problem [Solved]

An area to discuss 8-bit PIC specific problems and examples

Moderator: Benj

Post Reply
User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

PIC16F1508 Timer 2 and PWM Component Problem [Solved]

Post by QMESAR »

Hi All.

Happy New year to all ,I wish you all of the best for 2018 .

There seams to be 2 errors in the PWM component for PIC16F508
(1) The Timer 2 pre-scaler can only be set to 16 as maximum and the actual device has maximum pre-scaler of 64,
(2) when compiling the PWM results in an error when the PWM Enable function(makro) is called

:D Have good time
Attachments
1.jpg
1.jpg (64.06 KiB) Viewed 4708 times
2.jpg
2.jpg (46.76 KiB) Viewed 4708 times
3.jpg
3.jpg (226.51 KiB) Viewed 4708 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: PIC16F1508 Timer 2 and PWM Component Problem

Post by Benj »

Hi Peter,

The attached definitions now have the /64 prescaler for the Timer2 interrupt and PWM.

Simply extract the files into your "Flowcode 7/FCD/PIC" folder and restart Flowcode.
PIC.zip
(24.52 KiB) Downloaded 183 times
As for your compile errors it looks like you're out of memory on the device.

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

Hi Ben.
As for your compile errors it looks like you're out of memory on the device.
It can not be! the Flowchart only blinks a led and I try to add a PWM pin :shock:
When I call the function set dutycycle for the PWM component it compiles fine ,when I add the PWM Enable it generates the error
as you will see below compiling with out the PWM Enable it compiles fine
Attachments
12.jpg
12.jpg (69.01 KiB) Viewed 4694 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

Ben
I tested it again.
It compiles fine with the PWM component when I do not use the Enable call
when I call the PWM Enable the compiler throw an error
Attachments
12.jpg
12.jpg (36.79 KiB) Viewed 4692 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

Ben let me investigate this memeory story a bit will be back :D

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

Hi Ben.
attached the project it blinks only a LEd and Timer Interrupt
when using the enable PWM the compiler report errors and there is enough memory from what I can see from the compiler report
I have the feeling there is a component error some where :D

Thanks a million the Timer 2 prescaler is working well now :D :D
Attachments
p1508.rar
(66.44 KiB) Downloaded 179 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by LeighM »

Thanks for the investigations QMESAR,
The RET_VAL issue is just a warning, and will not stop compilation.

Without the original source it is difficult to know what exactly is going on, but I suspect that the addition of the call is just tipping the total RAM over the edge. Or, more importantly, the compiler cannot allocate all the various memory requirements into the space available. Fragmentation being the main issue.
It looks like the extra 6 bytes required for the Enable macro is stopping the compiler from finding the 39 bytes for text11

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: PIC16F1508 Timer 2 and PWM Component Problem

Post by medelec35 »

Just a guess.
As there is no issue with V6 :

Code: Select all

Target folder: M:\Flowcode Testing
Source name:   M:\Flowcode Testing\AC Module V1.fcfx
Title:         
Description:   
Device:        PIC.16F.16F1508
Generated by:  Flowcode v6.1.4.0
Date:          Wednesday, January 03, 2018 13:46:07
Users:         1
Registered to: Martin <Removed>
Licence key:   JQE1YE
http://www.matrixtsl.com
Launching the compiler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostc_16F.exe  -v -t PIC16F1508 "AC Module V1.c"
Launching BoostC...
BoostC Optimizing C Compiler Version 7.20 (for PIC16 architecture)
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday

Licensed to FlowCode User under Single user Pro License for 1 node(s)
Limitations: PIC12,PIC16 max code size:Unlimited, max RAM banks:Unlimited


AC Module V1.c
Starting preprocessor: "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\pp.exe" "AC Module V1.c" -i "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\include" -d _PIC16F1508 -la -c2 -o "AC Module V1.pp" -v -d _BOOSTC -d _PIC16 -d _PIC16x -d _CHAR_INDEX 

......................
AC Module V1.c success

success
Completed BoostC compilation, return = 0

Launching the linker/assembler...
C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\boostlink_picmicro.exe  -ld "C:\Program Files (x86)\Flowcode 6\compilers\pic\boostc\lib" libc_16F.lib rand_16F.lib float_16F.lib "AC Module V1.obj" -t PIC16F1508 -d "M:\Flowcode Testing" -p "AC Module V1" -swcs 6 2
BoostLink Optimizing Linker Version 7.20
http://www.sourceboost.com
Copyright(C) 2004-2013 Pavel Baranov
Copyright(C) 2004-2013 David Hobday


Warning unreferenced functions removed:
	 FC_CAL_Port_In__x	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
	 FC_CAL_Port_Out__x	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
	 FC_CAL_Port_Out_DDR__x	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_IO.c
	 Wdt_Delay_S	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 Wdt_Delay_Ms	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 FCI_DELAYINT_US	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 FCI_DELAYINT_MS	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 FCI_DELAYINTWDT_MS	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 FCI_DELAYINT_S	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 FCI_DELAYINTWDT_S	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Delay.c
	 FCI_GETCHAR	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_GETLENGTH	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_MIDSTRING	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_LEFTSTRING	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_RIGHTSTRING	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOSTRING	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOSTRS16	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOSTRS32	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOSTRU16	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOSTRU32	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOLOWER	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_TOUPPER	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_COMPARE	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_FLOAT_TO_STRING	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_NUMBER_TO_HEX	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_STRING_TO_INT	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_STRING_TO_FLOAT	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_STRREV	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_STRMOV	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_SHEAD	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 FCI_SCOPY	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_String.c
	 isinf	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 pow	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 flt_round	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 flt_floor	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 flt_ceil	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 flt_atan	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 cos	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 sin	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 tan	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_Float.c
	 FCD_0ba71_PWM_Digital__ReadASCIILUT	 in: M:\Flowcode Testing\AC Module V1.c
	 FC_CAL_PWM_Disable_1	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_PWM.c
	 FC_CAL_PWM_SetDuty8Bit_1	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_PWM.c
	 FC_CAL_PWM_SetDuty10Bit_1	 in: C:\Program Files (x86)\Flowcode 6\CAL\PIC\PIC_CAL_PWM.c
	 FCD_0df41_PWM1__ChangePeriod	 in: M:\Flowcode Testing\AC Module V1.c
	 FCD_0df41_PWM1__Disable	 in: M:\Flowcode Testing\AC Module V1.c
	 FCD_0df41_PWM1__SetDutyCycle	 in: M:\Flowcode Testing\AC Module V1.c
	 FCD_0df41_PWM1__SetDutyCycle10Bit	 in: M:\Flowcode Testing\AC Module V1.c

Building CASM file
Memory Usage Report
===================
RAM available:256 bytes, used:40 bytes (15.7%), free:216 bytes (84.3%), 
Heap size:216 bytes, Heap max single alloc:95 bytes
ROM available:4096 words, used:197 words (4.9%), free:3899 words (95.1%)



success


FINISHED
You can see there is plenty of RAM free,
Could the issue be an XC8 compiler bug in free mode?
Reason I suggest that is in pro mode, this is memory consumed :

Code: Select all

Memory Summary:
    Program space        used    86h (   134) of  1000h words   (  3.3%)
    Data space           used     Ah (    10) of   100h bytes   (  3.9%)
    EEPROM space         None available
    Data stack space     used     0h (     0) of    F0h bytes   (  0.0%)
    Configuration bits   used     2h (     2) of     2h words   (100.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)


Launching the linker/assembler...
C:\Program Files (x86)\Flowcode 7\tools\DoNothing\DoNothing.exe  


FINISHED
With V7 pro you can see both Program and Data space used is under 4%
Martin

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

Guys
It something strange but see my other post just adding the pwm component the memory usage increase by 50% ,I will now run the PWM with a normal C code function and see the memory usage ,

I am confused here

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

@martin
I dought it is the free mode causing the issue the exacty same Flowchart just in C Code in MPLAB pleanty of memory left.

I am confused
Attachments
15.jpg
15.jpg (117.14 KiB) Viewed 4678 times

User avatar
QMESAR
Valued Contributor
Valued Contributor
Posts: 1287
Joined: Sun Oct 05, 2014 3:20 pm
Location: Russia
Has thanked: 384 times
Been thanked: 614 times
Contact:

Re: PIC16F1508 Timer 2 and PWM Component Problem

Post by QMESAR »

Guys Thanks any how I have it now in C code I will just carry on there ,
Edit,
may be we are on something I will give it ago again :D

Have good time
:D

Post Reply