Author Topic: PIC16F1829 Capacitive Sensing Module Problem  (Read 5016 times)

0 Members and 1 Guest are viewing this topic.

Offline EngTiagoTopic starter

  • Newbie
  • Posts: 4
PIC16F1829 Capacitive Sensing Module Problem
« on: July 09, 2014, 10:00:17 pm »
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: [Select]
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
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC16F1829 Capacitive Sensing Module Problem
« Reply #1 on: July 09, 2014, 10:30:13 pm »
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?
« Last Edit: July 09, 2014, 10:39:25 pm by dannyf »
================================
https://dannyelectronics.wordpress.com/
 

Offline EngTiagoTopic starter

  • Newbie
  • Posts: 4
Re: PIC16F1829 Capacitive Sensing Module Problem
« Reply #2 on: July 10, 2014, 08:37:35 am »
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
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC16F1829 Capacitive Sensing Module Problem
« Reply #3 on: July 10, 2014, 10:37:28 am »
You can work on CPSCHxx bits individually, or if you change CPSCH to 4, and assign the corresponding values to CPSCH.
================================
https://dannyelectronics.wordpress.com/
 

Offline EngTiagoTopic starter

  • Newbie
  • Posts: 4
Re: PIC16F1829 Capacitive Sensing Module Problem
« Reply #4 on: July 10, 2014, 12:17:47 pm »
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".
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC16F1829 Capacitive Sensing Module Problem
« Reply #5 on: July 10, 2014, 01:06:15 pm »
1. Use the following to set to CPS ch 9:

Code: [Select]
  CPSH3=1, CPSH2=0, CHSH1=0, CHSH0=1; //set to cps chnnel 0b1001=9

You 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 to

Code: [Select]
       unsigned CPSCH :4;  //was 3

and,

2.2 use CPSCH as such:

Code: [Select]
  CPSCH=9; //set to cps channel 9
================================
https://dannyelectronics.wordpress.com/
 

Offline EngTiagoTopic starter

  • Newbie
  • Posts: 4
Re: PIC16F1829 Capacitive Sensing Module Problem
« Reply #6 on: July 10, 2014, 01:51:25 pm »
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...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->