CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Some of the PIC pics cant output 5V (SOLVED)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FermiTin



Joined: 03 Dec 2018
Posts: 12

View user's profile Send private message

Some of the PIC pics cant output 5V (SOLVED)
PostPosted: Mon Dec 03, 2018 2:41 pm     Reply with quote

Hey everyone. I googled and googled and couldnt find an anwser.

I have a pic18f24k22. The pic is connected to a few transistors and buttons. Outputs and inputs of pins like RC0 RC1 RA4 RA6 work, i can use them as both digital inputs and outputs.

The problems is with the analog pins (ex. RA2, RA3, RA5 and just any pin, that has an Analog ANx value). I cannot output from them (ex. PIN_C5).

Also an interesting problem, is PIN_A7, the output doesnt work either, but PIN_A6 works perfectly.

Why do some pins works and others not? especially the analog ones?

All of the pins tested ar not connected to anything, they are just bare pins. The other pins while testing work perfectly.

main.c
Code:

#include <main.h>

void main() {
   while(TRUE){
      output_high(PIN_A7);
      //PIN_C5 doesnt work either
   }

}


main.h
Code:

#include <18F24K22.h>
#device ADC=10
#INCLUDE <STDLIB.H>           //Needed for srand()


#FUSES NOWDT                  //No Watch Dog Timer

#use delay(internal=1000000)


Last edited by FermiTin on Fri Dec 07, 2018 1:57 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: Some of the PIC pics cant output 5V
PostPosted: Mon Dec 03, 2018 3:38 pm     Reply with quote

FermiTin wrote:
PIN_A7, the output doesnt work either, but PIN_A6 works perfectly.

Add the INTRC_IO fuse. That will fix it.

How about posting a full test program that demonstrates all the pins
that don't work ? I have the feeling that your real program has lines
of code that you are not showing us, that are causing the problem.

Also post your compiler version. It's a 4 digit number at the top of the
.LST file. Example: 5.081.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Mon Dec 03, 2018 5:28 pm     Reply with quote

By and large pins with analogue function default to analogue.
They won't work as digital if don't disable the analogue function.
Have you done this?

Mike
temtronic



Joined: 01 Jul 2010
Posts: 9232
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Dec 03, 2018 5:53 pm     Reply with quote

Mike brings up a GREAT point..something that would be obviously seen in a posted program. Historically , you've got to disable( turn off) any/all peripherals that can be accessed by I/O pins, if you need simple I/O.
That would include ADC, COMP, etc. My 'pet peeve' is that the PIC and compiler should default to all 'simple I/O' ,since... in the beginning that's all a PIC had...what came later are 'optional features' to me. Smile

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 03, 2018 6:08 pm     Reply with quote

Actually, you don't have to do all that stuff. The compiler does it for you.
Compile his posted program and look at the compiler generated code at
the start of main(). I've add comments on what it does:
Code:

.................... void main() { 
0004:  CLRF   TBLPTRU
0006:  BCF    RCON.IPEN
0008:  MOVLW  30
000A:  MOVWF  OSCCON
000C:  BCF    OSCTUNE.PLLEN
000E:  BCF    OSCTUNE.INTSRC
0010:  MOVLB  F
0012:  CLRF   x38  // ANSELA = 0x00  (make it all digital pins)
0014:  CLRF   x39  // ANSELB = 0x00  (make it all digital pins)
0016:  CLRF   x3A  // ANSELC = 0x00  (make it all digital pins)
0018:  CLRF   CM2CON1   // Disable comparator features
001A:  CLRF   CM2CON0   // Comparator 2 disabled
001C:  CLRF   CM1CON0   // Comparator 1 disabled
001E:  CLRF   04        // strtok.save = 0x0000
0020:  CLRF   05
..................

However, it's possible that he has some early version that doesn't do this.
That's why I asked for his version number.
FermiTin



Joined: 03 Dec 2018
Posts: 12

View user's profile Send private message

PostPosted: Tue Dec 04, 2018 1:03 am     Reply with quote

Okay, here is the version of the compiler: CCS PCH C Compiler, Version 5.074, xxxxx

This is the complete code, everything not shown is completely commented out.
Code:

#include <main.h>

void main() {
   setup_adc_ports(NO_ANALOGS);
   //Initializes starting pin values
   init();

   
   
   while(TRUE){
      output_high(green_tran);
   }

}



//Initializes starting pin values
void init(void){
   output_low(red_tran);
   output_low(yellow_tran);
   output_low(blue_tran);
   output_low(green_tran);
   output_low(red_led);
   output_low(yellow_led);
   output_low(blue_led);
   output_low(green_led);
}


main.h
Code:

#include <18F24K22.h>
#device ADC=10
#INCLUDE <STDLIB.H>           //Needed for srand()


#FUSES NOWDT  INTRC_IO                //No Watch Dog Timer

#use delay(internal=1000000)

#define red_led      PIN_C0 
#define yellow_led   PIN_C1
#define blue_led     PIN_A4
#define green_led    PIN_A6

#define red_tran     PIN_A1
#define yellow_tran  PIN_A3
#define blue_tran    PIN_A5
#define green_tran   PIN_A7  //not working

void init(void);


The PIN_A7 is unconnected. I checked the voltage and its 0.03V. When i tested the other pins from the same ground point, those pins work, so i am certain its not the testing that is the problem. Even with the fuse, the A7 pin doesnt work.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 04, 2018 2:13 am     Reply with quote

Are you sure you're looking at the correct pin ? What PIC package are
you using ? What physical pin number are you probing ?

Also, look at the list of fuses at the end of your .LST file. Make sure that
it has the INTRC_IO fuse as the first one as shown below:
Code:

Configuration Fuses:
   Word  1: E800   INTRC_IO NOPLLEN PRIMARY FCMEN IESO
   Word  2: 3C1E   PUT BROWNOUT BORV19 NOWDT WDT32768
   Word  3: BF00   CCP2C1 PBADEN CCP3B5 HFOFST TIMER3C0 CCP2B5 MCLR
   Word  4: 0081   STVREN NOLVP NOXINST NODEBUG
   Word  5: C003   NOPROTECT NOCPB NOCPD
   Word  6: E003   NOWRT NOWRTC NOWRTB NOWRTD
   Word  7: 4003   NOEBTR NOEBTRB
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Tue Dec 04, 2018 3:02 am     Reply with quote

Er....

Just compiled the posted code, on his compiler version. Ran it through on
MPLAB. Everything looks good. The ANSEL registers are all correctly
programmed etc.. There is an issue though that the primary clock is
hardware enabled. Though not being used (internal oscillator), this leaves
the oscillator input pin committed to this oscillator.
(visible in PCM_Programmer's fuses above).

Set the fuses as:

#FUSES NOWDT, INTRC_IO , PRIMARY_SW //No Watch Dog Timer

and the pin should become available for normal use.

As a comment, can I suggest it is better to always leave includes till
_after_ the chip is configured. So:

Code:

#include <18F24K22.h>
#device ADC=10

#FUSES NOWDT, INTRC_IO, PRIMARY_SW

#use delay(internal=1000000)

#INCLUDE <STDLIB.H>           //Needed for srand()


If you include something that uses stdio, or something that relies on
timings, _before_ these are setup, it will lead to issues. Always safer
to set the chip up, and only then include thing... Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9232
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Dec 04, 2018 8:02 am     Reply with quote

re: PCM P's comment.....
I don't trust the compiler for 'defaults'...been 'bit' a few times in the past. I like to see my code control the setup / config of the PICs.
It's not just the compiler, rather 'defaults' in general.

Jay
FermiTin



Joined: 03 Dec 2018
Posts: 12

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 2:21 am     Reply with quote

Still not working. 9 pin (PIN_A7) is 0.02V. main.c is the same, main.h is updated:

main.h
Code:

#include <18F24K22.h>
#device ADC=10

#FUSES NOWDT, INTRC_IO , PRIMARY_SW       //No Watch Dog Timer

#use delay(internal=1000000)

#INCLUDE <STDLIB.H>           //Needed for srand()

#define red_led      PIN_C0 
#define yellow_led   PIN_C1
#define blue_led     PIN_A4
#define green_led    PIN_A6

#define red_tran     PIN_A1
#define yellow_tran  PIN_A3
#define blue_tran    PIN_A5
#define green_tran   PIN_A7  //not working

void init(void);


My PIC is PIC18F24K22 DIP.

https://imgur.com/a/uWQwqj7

Btw, how do i embed pictures?

I checked the fuses, and they are listed in the correct order, just like the ones you gave in the example.

Configuration Fuses:
Word 1: C800 INTRC_IO NOPLLEN PRIMARY_SW FCMEN IESO
Word 2: 3C1E PUT BROWNOUT BORV19 NOWDT WDT32768
Word 3: BF00 CCP2C1 PBADEN CCP3B5 HFOFST TIMER3C0 CCP2B5 MCLR
Word 4: 0081 STVREN NOLVP NOXINST NODEBUG
Word 5: C003 NOPROTECT NOCPB NOCPD
Word 6: E003 NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 4003 NOEBTR NOEBTRB
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 2:48 am     Reply with quote

What is connected to Pin A7 (pin 9 on the PIC) on your board ?
FermiTin



Joined: 03 Dec 2018
Posts: 12

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 2:55 am     Reply with quote

Nothing, just like in the picture. The other pins, non analog work fine.
Ttelmah



Joined: 11 Mar 2010
Posts: 19529

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 3:52 am     Reply with quote

Honestly on the photograph it is not possible to be 'sure'. There are whiskers
coming out of the pin and (importantly), there seem to be whiskers visible from
the Vss connection next door, that could be making contact with the pin.
Magnifying glass and scalpel, and make sure it is not making contact to
anything else.
FermiTin



Joined: 03 Dec 2018
Posts: 12

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 4:00 am     Reply with quote

Multimeter continuity test doesnt show a connection on either sides of the pin.

For now, im installing MPLABX and see if it is a CCS C problem.
FermiTin



Joined: 03 Dec 2018
Posts: 12

View user's profile Send private message

PostPosted: Thu Dec 06, 2018 6:11 am     Reply with quote

Looks like using mplabx didnt work either.
Code:

// PIC18F24K22 Configuration Bit Settings

// 'C' source line config statements

// CONFIG1H
#pragma config FOSC = ECHPIO6   // Oscillator Selection bits (EC oscillator (high power, >16 MHz))
#pragma config PLLCFG = OFF     // 4X PLL Enable (Oscillator used directly)
#pragma config PRICLKEN = ON    // Primary clock enable bit (Primary clock enabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power-up Timer Enable bit (Power up timer disabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 190       // Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal)

// CONFIG2H
#pragma config WDTEN = ON       // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect)
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = PORTC1  // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF      // PORTB A/D Enable bit (PORTB<5:0> pins are configured as analog input channels on Reset)
#pragma config CCP3MX = PORTB5  // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
#pragma config HFOFST = ON      // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
#pragma config T3CMX = PORTC0   // Timer3 Clock input mux bit (T3CKI is on RC0)
#pragma config P2BMX = PORTB5   // ECCP2 B output mux bit (P2B is on RB5)
#pragma config MCLRE = EXTMCLR  // MCLR Pin Enable bit (MCLR pin enabled, RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled if MCLRE is also 1)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

#define _XTAL_FREQ 1000000

#include <xc.h>

int main()
{
  TRISA7 = 0; //RA7 as Output PIN
  while(1)
  {
    LA7 = 1;  // LED ON
    __delay_ms(1000); // 1 Second Delay
  }
  return 0;
}

Changed out PIC's but both of theres pina7 doesnt work.[/code]
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group