PIC16F1829 Capacitive Sensing Module Problem - Page 1
Forum section: electronics / general

author: EngTiago
author_rank: Newbie
timestamp: July 09, 2014, 10:00:17 pm
content: Hi all,I'm using a PIC16F1829 with MPLAB X IDE v2.00 and xc8 v1.32 compiler in a project with the Capacitive Sensing Module.I need to use all of the 12 CPS input channels that supposly i have but everytime i use a channel above 7 i get the following warning message "main.c:49: warning: (762) constant truncated when assigned to bitfield".I already checked the header file pic16f1829.h and i notice this:Code:typedef union {struct {unsigned CPSCH0 :1;unsigned CPSCH1 :1;unsigned CPSCH2 :1;unsigned CPSCH3 :1;};struct {unsigned CPSCH :3;};} CPSCON1bits_t;So i have 3 bits in CPSCH field where it supposed to be 4 bits to choose between CPS0 & CPS11.I have no problem using the first 7 channels but when using the rest of them i have no control and i get the warning i just said.In the page 316 of Datasheet (note1) said that in this PIC i have all of the 12 channels available....but it seems i don't.I think this is an header file problem but i have no sure and i can't find any information about this online.I would like some help on this...Best regards to you all

author: dannyf
author_rank: Super Contributor
timestamp: July 09, 2014, 10:30:13 pm
content: Yes, it does look like the header file is wrong. Should have been 4 rather than 3.Would it work if you use individual bits?

author: EngTiago
author_rank: Newbie
timestamp: July 10, 2014, 08:37:35 am
content: Hi,what did you mean with "individual bits"? I found another compiler(SDCC) that have all four bits, so i think this is a XC8 compiler problem.Thks

author: dannyf
author_rank: Super Contributor
timestamp: July 10, 2014, 10:37:28 am
content: You can work on CPSCHxx bits individually, or if you change CPSCH to 4, and assign the corresponding values to CPSCH.

author: EngTiago
author_rank: Newbie
timestamp: July 10, 2014, 12:17:47 pm
content: Hi,CPSCHxx is only between CPSH0 and CPSH3 when individual bits are used. I can use the CPSCH to set the channel i want but only up to 7. If i set CPSCH to 8 or above the channel dont work and i get the warning message "main.c:49: warning: (762) constant truncated when assigned to bitfield".

author: dannyf
author_rank: Super Contributor
timestamp: July 10, 2014, 01:06:15 pm
content: 1. Use the following to set to CPS ch 9:Code:CPSH3=1, CPSH2=0, CHSH1=0, CHSH0=1; //set to cps chnnel 0b1001=9You may need to bring out the struct CPSCON1bits to do that.or,2. use CPSH to set to CPS ch 9:2.1 change CPSCON1 declaration in the header file toCode:unsigned CPSCH :4; //was 3and,2.2 use CPSCH as such:Code:CPSCH=9; //set to cps channel 9

author: EngTiago
author_rank: Newbie
timestamp: July 10, 2014, 01:51:25 pm
content: Hello again,I already check what you said and you're right, i was thinking wrong about the meaning of CPSH3 to CPSH0.Just one last thing, when i use individual bits to config some channel, the other ones that are configured through the CPSCH (and previously working) don't work anymore. So, if i use the "bit-a-bit" configuration i have to use that way to configure all channels? I think that doesn't make sense, but it was happened and i can't understand why.Thanks for your help...