View previous topic :: View next topic |
Author |
Message |
JacquesB
Joined: 22 Aug 2008 Posts: 21
|
Using Internal Oscillator and getting back 2 IOs |
Posted: Tue Mar 10, 2009 12:54 pm |
|
|
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
|
|
Posted: Tue Mar 10, 2009 1:16 pm |
|
|
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
|
|
Posted: Tue Mar 10, 2009 1:57 pm |
|
|
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
|
|
Posted: Tue Mar 10, 2009 2:33 pm |
|
|
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
in between each line.
If no change, then
etc.
Do some testing. |
|
|
JacquesB
Joined: 22 Aug 2008 Posts: 21
|
|
Posted: Tue Mar 10, 2009 2:34 pm |
|
|
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 |
|
|
|