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 support@ccsinfo.com

Using Internal Oscillator and getting back 2 IOs

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



Joined: 22 Aug 2008
Posts: 21

View user's profile Send private message

Using Internal Oscillator and getting back 2 IOs
PostPosted: Tue Mar 10, 2009 12:54 pm     Reply with quote

Hi,

I'm trying to use OSC0 & OSC1 pin as general purpose IOs (RA6 & RA7) but I can't make one of them work.

I'm using a PIC18F2525 on a PICDEM2 plus eval board and the compiler is 4.071.
Using a simple test program, I can toggle pin RA6 but when I try to change RA7 I only see a glitch.
It come back to 0V.

My test program is:

Code:
#include <18F2525.h>         
#device ICD=TRUE
#device adc=8

#FUSES NOWDT
#FUSES WDT128                   
#FUSES INTRC_IO      // Internal OSC >> Important to get control over RA6 & RA7
#define FRQ 4000000            
#use delay(clock=FRQ)

void main(void)
{
   int16 i;
   setup_oscillator(OSC_4MHZ|OSC_INTRC);      
   port_b_pullups(TRUE);                  //

   output_a(0xFF);
   setup_adc_ports(NO_ANALOGS|VSS_VDD);      
   setup_adc(ADC_OFF|ADC_TAD_MUL_0);         
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   output_a(0x00);      // RA6 &RA7 =1
   output_a(0x40);      // RA6=1
   output_a(0x80);     // glitch on RA7
   output_a(0xC0);      // RA6=1 glitch on RA7
}

Also to make sure that the prototype is not the problem I've disconnected RA7 from the pcb
and attached the scope directly to it.
Is there something else that needs to be done in order to get control of RA7?

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 1:16 pm     Reply with quote

Try this test program which just toggles Pin A7. What do you see on the
oscilloscope ?
Code:
#include <18F2525.h>         
#fuses INTRC_IO,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)

//======================================
void main(void)
{

while(1)
  {
   output_high(PIN_A7);
   delay_ms(1);
   output_low(PIN_A7);
   delay_ms(1);
  }

}
JacquesB



Joined: 22 Aug 2008
Posts: 21

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 1:57 pm     Reply with quote

It works , I 've got a 500Hz signal !

I don't understand why output_high(PIN_A7); works but not
output_a(0x80);

I need to change RA6 & Ra7 both at the same time. That's why I've used Output_a().

Do you have any clue?

Thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 2:33 pm     Reply with quote

Quote:
output_a(0x00); // RA6 &RA7 =1
output_a(0x40); // RA6=1
output_a(0x80); // glitch on RA7
output_a(0xC0); // RA6=1 glitch on RA7

Put short delays in between these lines of code. You're running at a
1 MHz instruction rate, so 1 us is the shortest delay possible.

Try
Code:
delay_us(1);

in between each line.

If no change, then
Code:
delay_us(5);

etc.

Do some testing.
JacquesB



Joined: 22 Aug 2008
Posts: 21

View user's profile Send private message

PostPosted: Tue Mar 10, 2009 2:34 pm     Reply with quote

After replacing output_high(PIN_A7); & output_high(PIN_A6);
by
output_a(0x80); & output_a(0xC0); ....

I got the same 500hz signal
I don't know what I was doing wrong at the beginning but I think the case is closed. It works both way the way it should.


Thanks for the clue
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