Page 1 of 1

FC7 Compile-to-Hex fails on PIC 18F2331

Posted: Fri Jul 22, 2016 12:00 pm
by triokenwood
Whilst trying to develop a small motor-control interface, I was unable to get the code to compile to HEX without fatal errors.
In trying to isolate the issue, I reduced the code to the following, ultra-simple, segment:-
18F2331 test A2D.JPG
18F2331 test A2D.JPG (21.9 KiB) Viewed 6738 times
This code does not compile – neither on Flowcode 7 Beta, nor on the very latest release (downloaded and installed yesterday evening)

This is the relevant section of the error message:-

Code: Select all

C:\Program Files (x86)\Flowcode 7\CAL\PIC\PIC_CAL_ADC.c: FC_CAL_ADC_Enable()
  1933:    ADCON0bits.VCFG0 = 1;
                      ^ (255) not a member of the struct/union ""
                         ^ (182) illegal conversion between types
In trying to resolve the issue, I modified the project to use the 16F877 and also to use a 16F88 (the actual project requires the 18F2331). On both the 16F88 and 16F877 devices, the code compiles successfully – only failing when trying to use the 18F2331

Further investigation of the actual C file referenced in the error message showed that there was a pretty close similarity between the code segment for “ADC Type 2 Supported Devices (which included the 16F88) and “ADC Type 14 Supported Devices” (the 18F2331)

Extracts of these two C-code segments are shown below:-

For the 16F88

Code: Select all

// ADC Type 2 Supported Devices ************************************************************
// 16F88
// *****************************************************************************************/

#ifdef MX_ADC_TYPE_2
     void FC_CAL_ADC_Enable (MX_UINT8 Channel, MX_UINT8 Conv_Speed, MX_UINT8 Vref, MX_UINT8 T_Charge)
     {
           if (Vref == 1)                                                         //assign VREF functionality
                st_bit(ADCON1, VCFG1);

           switch (Channel)
           {
                #ifdef MX_ADC_CHANNEL_0
                      case (0):
                           tris_mask = 0x01;
                           tris_reg = &TRISA;
                           ANSEL = 0x01;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_1
                      case (1):
                           tris_mask = 0x02;
                           tris_reg = &TRISA;
                           ANSEL = 0x02;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_2
                      case (2):
                           tris_mask = 0x04;
                           tris_reg = &TRISA;
                           ANSEL = 0x04;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_3
                      case (3):
                           tris_mask = 0x08;
                           tris_reg = &TRISA;
                           ANSEL = 0x08;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_4
                      case (4):
                           tris_mask = 0x10;
                           tris_reg = &TRISA;
                           ANSEL = 0x10;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_5
                      case (5):
                           tris_mask = 0x20;
                           tris_reg = ⧍
                           ANSEL = 0x20;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_6
                      case (6):
                           tris_mask = 0x40;
                           tris_reg = ⧍
                           ANSEL = 0x40;
                           break;
                #endif
           }
For the 18F2331

Code: Select all

// ADC Type 14 Supported Devices ***********************************************************
// 18F2331, 18F2431, 18F4331, 18F4431
// *****************************************************************************************/

#ifdef MX_ADC_TYPE_14
     void FC_CAL_ADC_Enable (MX_UINT8 Channel, MX_UINT8 Conv_Speed, MX_UINT8 Vref, MX_UINT8 T_Charge)
     {
           ADCON1 = 0x00;                                                         //set up ADC conversion
           ADCON2 = Conv_Speed & 0x07;
           ADCON3 = 0x00;
           ADCHS = 0x00;

           switch (Channel)
           {
                #ifdef MX_ADC_CHANNEL_0
                      case (0):
                           tris_mask = 0x01;
                           tris_reg = &TRISA;
                           ADCON0 = 0x00;
                           ANSEL0 = 0x01;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_1
                      case (1):
                           tris_mask = 0x02;
                           tris_reg = &TRISA;
                           ADCON0 = 0x04;
                           ANSEL0 = 0x02;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_2
                      case (2):
                           tris_mask = 0x04;
                           tris_reg = &TRISA;
                           ADCON0 = 0x08;
                           ANSEL0 = 0x04;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_3
                      case (3):
                           tris_mask = 0x08;
                           tris_reg = &TRISA;
                           ADCON0 = 0x0C;
                           ANSEL0 = 0x08;
                #endif
                #ifdef MX_ADC_CHANNEL_4
                      case (4):
                           tris_mask = 0x10;
                           tris_reg = &TRISA;
                           ADCON0 = 0x00;
                           ADCHS = 0x01;
                           ANSEL0 = 0x10;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_5
                      case (5):
                           tris_mask = 0x20;
                           tris_reg = &TRISA;
                           ADCON0 = 0x04;
                           ADCHS = 0x10;
                           ANSEL0 = 0x20;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_6
                      case (6):
                           tris_mask = 0x01;
                           tris_reg = &TRISE;
                           ADCON0 = 0x08;
                           ADCHS = 0x04;
                           ANSEL0 = 0x40;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_7
                      case (7):
                           tris_mask = 0x02;
                           tris_reg = &TRISE;
                           ADCON0 = 0x0C;
                           ADCHS = 0x40;
                           ANSEL0 = 0x80;
                           break;
                #endif
                #ifdef MX_ADC_CHANNEL_8
                      case (8):
                           tris_mask = 0x04;
                           tris_reg = ⧍
                           ADCON0 = 0x00;
                           ADCHS = 0x02;
                           ANSEL1 = 0x01;
                           break;
                #endif
           }

           old_tris = *tris_reg;                                            //store old tris value, and set the i/o pin as an input
           *tris_reg = old_tris | tris_mask;
           ADCON0 = ADCON0 | 0x01;                                                //turn ADC on

           if (Vref != 0)                                                         //assign VREF functionality
                st_bit(ADCON0, VCFG0);

           delay_us(T_Charge);                                                    //wait the acquisition time

           ADCON0 = ADCON0 | 0x02;                                                //begin next conversion
     }
I then tried to adapt the code for the Type 14 devices, by using the code from the Type 2 section:-

Code: Select all

if (Vref == 1)                                                         //assign VREF functionality
                st_bit(ADCON1, VCFG1);
This, at last, allowed the code to compile to HEX – I have not tried programming a chip as I am still developing the main code itself.
However, the main code also now compiles to HEX – so I can now see how much code memory I have left to work with.

I have attached the modified C file which I am now using to allow my project to move forward.

Could someone with better knowledge of low-level programming and configuration of PIC chips please look into this matter and,
a.) Determine if I have identified a valid ‘bug’
b.) Verify that my proposed solution is actually ‘correct’

Any, and all, help would be greatly appreciated.

Cheers,
Bill

Re: FC7 Compile-to-Hex fails on PIC 18F2331

Posted: Fri Jul 22, 2016 12:37 pm
by LeighM
Hi Bill,
Thanks for that, yes you are correct it should be ADCON1.
Although the VCFG0 is correct, as the 18F2331 VCFG1:VCFG0 bits need to be 01 to assign VREF+ to external (which is the usual understanding for the component)
Thanks again for the spot.
I've attached our accordingly updated version.
Regards,
Leigh

Re: FC7 Compile-to-Hex fails on PIC 18F2331

Posted: Fri Jul 22, 2016 1:00 pm
by triokenwood
Great - thanks for the rapid response Leigh.

It makes all the effort that Niall and I put into getting things going seem worthwhile (especially since neither of us have any 'formal' training in any kind of programming language, but are merely just 'key bashers', always trying our best to overcome obstacles put in our way to annoy us :cry:

I'll get your file downloaded and (hopefully) move on!

Cheers,
Bill