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

strange problem on 18f4620

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



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

strange problem on 18f4620
PostPosted: Tue Dec 30, 2008 3:23 pm     Reply with quote

this program runs ok on 877 but not on 18f4620

Code:
#include <18f4620.h>
#fuses HS,NOWDT,PUT,NOBROWNOUT,NOLVP
#device ADC=10
#use delay (clock=10000000)
#byte portb=6
#byte porta=5
#byte portc=7
#use RS232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


int c=0;
int16 value=0;
int flag=0;
#int_rtcc
void rtcc_isr(){         

set_RTCC(125);
output_low(pin_b7);         
set_adc_channel(0);     
         
value = read_ADC();     
 output_high(pin_b7);
printf ("A %ld\n",value);   
       

               
                       }

void main(){

set_tris_a(0x1f);
set_tris_b(0x00);
set_tris_c(0x00);
setup_adc_ports( all_analog);
setup_adc(ADC_CLOCK_DIV_32);
setup_counters(RTCC_internal,RTCC_div_16);
set_RTCC(125);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
PORTA=0x00;
PORTB=0x00;
PORTC=0x00;

while(1)   {
           
              }
            }
                 

I tested on a oscilloscope
and result is :
on 16f877 I have one conversion every 0.8ms almost
(periodic)

But on 18f4620 I cannot measure when goes to interrupt!!
The oscilloscope confuses!!!
Very strange things!!
I can't explain more.

What can I do for this?
maybe some changes at code?
Ttelmah
Guest







PostPosted: Tue Dec 30, 2008 3:37 pm     Reply with quote

Start with the fact that you are using hardware port addresses. These are different on 18 family chips. You need to adjust these.
Acessing addresses at the bottom of memory on the 18, will overwrite the system storage area used for the interrupt temporary store...

Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 30, 2008 3:42 pm     Reply with quote

Download the 18F4620 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
Look in this section to find the correct addresses for the PortA, B, and C
registers for your PIC.
Quote:
5.3.4 SPECIAL FUNCTION REGISTERS


A better way is to use the CCS functions to set the port addresses,
such as output_a(), output_b(), and output_c(). Let the compiler handle
setting the TRIS for you. Don't try to set it yourself. If you use those
CCS functions, problems like this will not happen.
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Tue Dec 30, 2008 3:46 pm     Reply with quote

thanks for reply !!!


can you be more clearly? (my english are not so good to understand uSad )
what must i look?
is there a problem on code?
....................................................

to be honest i did not check this!!
thanks a lot both or you!!!
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Dec 30, 2008 3:54 pm     Reply with quote

Quote:
#byte portb=6
#byte porta=5
#byte portc=7
this is for the 16F877a


Quote:

should be for the 18F4620
#byte porta=0xF80
#byte portb=0xF81
#byte portc=0xF82
#byte portd=0xF83
#byte porte=0xF84

page 62 of spec
http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf


Last edited by treitmey on Tue Dec 30, 2008 3:56 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 30, 2008 3:55 pm     Reply with quote

Quote:
#include <18f4620.h>
#fuses HS,NOWDT,PUT,NOBROWNOUT,NOLVP
#device ADC=10
#use delay (clock=10000000)
#byte portb=6
#byte porta=5
#byte portc=7

#use RS232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

The lines shown in bold must be changed. The addresses of 5, 6, 7
are not correct for the 18F4620.

Download the 18F4620 data sheet:
http://ww1.microchip.com/downloads/en/DeviceDoc/39626e.pdf
Look in this section to find the correct addresses for the PortA, B, and C
registers for the 18F4620:
Quote:
5.3.4 SPECIAL FUNCTION REGISTERS
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Tue Dec 30, 2008 4:09 pm     Reply with quote

i very thank you!!

i change them as you say
but the problem continues
look..
i have the probe at PINB7
and the scale on osciloscope at 1ms and sometime 0.5ms
and the only thing i see is logic "1'
!!!!!!!!!!!!!!! no change at this pin!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 30, 2008 4:55 pm     Reply with quote

Quote:
I have the probe at PINB7 and the only thing i see is logic "1'


The pin is only low for about 2 or 3 micro-seconds. The functions shown
in bold execute in 2-3 us. Then pin B7 is set high, and it stays high
during the printf(), which takes several milli-seconds. Pin B7 will appear
to always be high on the oscilloscope.
Quote:
#int_rtcc
void rtcc_isr(){

set_RTCC(125);
output_low(pin_b7);
set_adc_channel(0);

value = read_ADC();

output_high(pin_b7);
printf ("A %ld\n",value);
}


My advice is to start with a more simple program.
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Wed Dec 31, 2008 1:45 am     Reply with quote

i change my program and put output_high(PIN_B7)
after printf
so, i see that pulses wasn't steady
i mean ,on 877 shows like a "train" pulse!!
on 4620 i have one pulse even .... i don't know !!!
i can't "catch" this wave .. i try to see in all scales on time division
on hyperterminal seems too work but very-very-very slow
even on 115200!!!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 31, 2008 2:34 am     Reply with quote

Try a more simple program. Don't put a printf() statement inside the
interrupt routine. Example:
http://www.ccsinfo.com/forum/viewtopic.php?t=24530&start=1
pvol



Joined: 10 Oct 2008
Posts: 46
Location: GREECE

View user's profile Send private message

PostPosted: Wed Dec 31, 2008 3:16 am     Reply with quote

well, after a few changes
i conclude that the program don't like RTCC very much

i write interrupt alone and the ADC at while (1)
and runs just fine!!!

#int_rtcc
void rtcc_isr(){
set_RTCC(125);
}
void main() {
setup_adc_ports( all_analog);
setup_adc(ADC_CLOCK_DIV_64);
setup_counters(RTCC_internal,RTCC_div_64);
set_RTCC(125);
enable_interrupts(INT_RTCC);
enable_interrupts(global);
while(1) {
output_high(pin_b7);
set_adc_channel(0);
value = read_ADC();
output_low(pin_b7);
printf ("A %ld\n",value);
}
}

now, i can see clearly PINB7 goes up and down!
i want to ask a few questions more..
how can i achieve the fastest A/D conversion on this PIC???
notice that i change fuses ..i put H4 with 10MHz crystal
and the delay clock becomes 40MHz
what else must i change >?
maybe this?setup_adc(ADC_CLOCK_DIV_64)?
data sheet can't tell me clearly.
thanks a lot
and i wish you to have a very happy and healthy 2009!
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