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

Input pin not responding [RESOLVED]

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
principia



Joined: 09 Sep 2010
Posts: 3

View user's profile Send private message

Input pin not responding [RESOLVED]
PostPosted: Thu Sep 09, 2010 4:41 pm     Reply with quote

I've been struggling with this problem on my own for too long now. It's particularly frustrating because it appears to be so simple! Please help!?

Setup: 18F45J11 running off internal clock at 8MHz. On pin B0, there is a 10k pullup resistor to 3.3V and switch to ground.
A simple program drives a couple of LEDs depending on the input switch position.

Problem: The MCU does not recognise the input level change on B0 - so the LEDs don't toggle. If I reconfigure software and hardware so that B3 is used instead of B0, it all works as expected, and the LEDs toggle. B0 is the only input I've had problems with.

Compiler: 4.112
Problem seen in Run and Debug.

I've run a similar program on a 18F4520 and it all works fine. I suspect I've messed up a fuse setting somewhere, but can I find it?!?!



Code:

#include <45j11 input test.h>

void main()
{
   setup_adc_ports(NO_ANALOGS|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

   set_tris_b(0x09);
   short my_led;
   output_high(PIN_B5);
   
    while(true){
      my_led=input(PIN_B0);
      //my_led=input(PIN_B3);
      output_bit(PIN_B1,~my_led);
      output_bit(PIN_B2,my_led);
    }
}


Code:

#include <18F45J11.h>
#device ICD=TRUE
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC                    //Internal RC Osc
#FUSES DEBUG                    //Debug mode for use with ICD
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NOSTVREN                 //Stack full/underflow will not cause reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOWPCFG               
#FUSES WPBEG                 
#FUSES WPDIS                 
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES T1DIG                 
#FUSES MSSPMSK7             
#FUSES DSWDT2147483648       
#FUSES NODSWDT             
#FUSES NODSBOR               
#FUSES RTCOSC_T1             
#FUSES DSWDTOSC_INT         
#FUSES WPFP         
         
#use delay(int=8000000)
#use standard_io(B)




Many thanks

Richard


Last edited by principia on Fri Sep 10, 2010 6:06 am; edited 2 times in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: Input pin not responding
PostPosted: Thu Sep 09, 2010 7:31 pm     Reply with quote

principia wrote:
Setup: 18F45J11 running off internal clock at 8MHz.

This doesn't match with:
Code:
#include <18F4520.h>
and
Code:
#use delay(clock=20000000)


Less important, but
Code:
   setup_spi(SPI_SS_DISABLED);
   setup_spi2(SPI_SS_DISABLED);
 
This is an error in the CCS code wizard. To turn SPI off you have to pass the FALSE parameter.
principia



Joined: 09 Sep 2010
Posts: 3

View user's profile Send private message

PostPosted: Fri Sep 10, 2010 12:55 am     Reply with quote

Thanks. Of course, I copied/pasted from the wrong header.... I've edited my original post now to show the contents of the correct file.

Also tried the setup_spi change.

But...still the same problem. By the way, I've repeated this on two separate boards, so I don't think there's a build fault on the hardware.

Richard
principia



Joined: 09 Sep 2010
Posts: 3

View user's profile Send private message

Resolved!
PostPosted: Fri Sep 10, 2010 6:05 am     Reply with quote

Now resolved after much frustration.
I had a detailed look at the registers associated with PORT B. It looks as if one of them, ANCON1, is not set correctly by the setup_adc_ports() or setup_adc() routines. The compiler was setting this to 0x0F rather than 0x1F. This means that the pin B0/AN12 was being configured as an A/D input and not a DIO.
So I have now forced this manually as follows:
Code:

#include <45j11 input test.h>

#byte ANCON1 = 0xF49

void main()
{
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_spi2(FALSE);
   setup_wdt(WDT_OFF);
   setup_timer_0(T0_OFF);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
   setup_timer_4(T4_DISABLED,0,1);
   setup_ccp1(CCP_OFF);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   setup_oscillator(OSC_8MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);

   short my_led;

   output_b(0);

   ANCON1 = 0x1F;

   set_tris_b(0x09);

   output_high(PIN_B5);
   
    while(true){
      my_led=input(PIN_B0);
      //my_led=input(PIN_B3);
      output_bit(PIN_B1,~my_led);
      output_bit(PIN_B2,my_led);
    }
}


Looks like a possible bug in the compiler do you think?
Thanks
Richard
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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