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

Problem in external /supportive circuit of PIC 18F452

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



Joined: 07 Feb 2012
Posts: 5
Location: Pakistan

View user's profile Send private message Send e-mail

Problem in external /supportive circuit of PIC 18F452
PostPosted: Mon Feb 13, 2012 7:07 am     Reply with quote

I have a problem with external /supported circuit of PIC18F452. I have a circuit but it is not properly work. I am working on I2C protocol. If any one have the supportive circuit of PIC18F452 the post it to me on my e - mail at wasim.comsats@gmail.com.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 7:21 am     Reply with quote

What version compiler are you using?
_________________
Google and Forum Search are some of your best tools!!!!
wasimakhlaq



Joined: 07 Feb 2012
Posts: 5
Location: Pakistan

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 13, 2012 7:32 am     Reply with quote

i m using CCS Complier 4.084. i burned the code in PIC18F452 kit it go runs well but when i make my own hardware(in breadboard) then it is not working i thing PIC 18F452 supportive circuit is not well so if you have the hardware supportive circuit then mail me.


regards..
temtronic



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

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 7:55 am     Reply with quote

What I2C device, what speed, what size pullup resistors on the I2C bus?
wasimakhlaq



Joined: 07 Feb 2012
Posts: 5
Location: Pakistan

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 13, 2012 7:57 am     Reply with quote

i want to communication between two PIC 18F452 kits with I2C protocol with crystal is 4Mhz and 47K pullup resistors.
Ttelmah



Joined: 11 Mar 2010
Posts: 19482

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 8:21 am     Reply with quote

47K is too large.

Fundamentally, each chip needs a clock source (you can use one crystal, but care is needed to ensure the line capacitance is fairly low). Connections then would be. One leg of crystal to OSC1. Second leg to OSC2. One small (typically 27pf) capacitor from OSC1 to GND. Wire from OSC2 on the first chip to OSC1 on the second. Depending on the length and design of this, try without a second loading capacitor on the crystal.

Then pull up resistor on MCLR of each chip to 5v. Perhaps 10KR.

5v supply to the Vdd pins of each chip.

Gnd to the Vss pins of each chip.

A small capacitor with good high frequency response (typically ceramic or polyester - perhaps 0.1uF) - close to the supply pins on each chip.

RC3 connected together between the chips, with a pull up resistor to 5v.

RC4 connected the same way between the chips.

Now I2C resistor size needed depends on the capacitance of the lines, and the speed you want to work, but the _maximum_ value it can have for a 5v bus with just 50pF capacitance (low), running at the standard speed, is 16KR. Hence my '47K is too large' comment. For a typical bus at a couple of hundred pF, 4.7KR resistor would be the maximum. Minimum value about 2KR.

Likely other problems with breadboard:

1) Too much capacitance on the processor clock lines.
2) Inadequate smoothing right by the chip.

Start by just writing a 'flash an LED' program, and get this working in each chip - verify it flashes at the right rate. Only once you are sure both chips are working, move to more complex things.

Best Wishes

Best Wishes
wasimakhlaq



Joined: 07 Feb 2012
Posts: 5
Location: Pakistan

View user's profile Send private message Send e-mail

PostPosted: Mon Feb 13, 2012 8:42 am     Reply with quote

Can you give me this detail in the form of a diagram because i am new to PIC 18F452.
mateeb4u@gmail.com



Joined: 07 Feb 2012
Posts: 19
Location: pakistan

View user's profile Send private message Send e-mail Yahoo Messenger

thanks to Ttelmah
PostPosted: Tue Feb 14, 2012 6:00 am     Reply with quote

Ttelmah i m working with wasim akhlaq

so our problem is combine before some days u also reply me on pic 12c protocol problem in proteous
actually we are 4.7k pull up resistor post 47k mistakenly
our main goal in our university project to interface TEA5767 IC
so at the first step our supervisor said to us u first communcate the two PICs then moves to IC (TEA567)

now i m posting Master program my PIC circuit
proteous image

master code
slave code
the IC controlling code


Master & TEA5767 Code is same:




Code:
#include<18F452.h>
#use delay(clock = 4000000)
//#use I2C(MASTER, SDA=PIN_B1, SCL=PIN_B0,FAST=400000)
#use I2C(MASTER,SLOW, SDA=PIN_B1, SCL=PIN_B0)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#fuses NOWDT,NOPROTECT,NOLVP,XT
//BYTE write_bit=0x0,read_bit=0x01;
/*#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
*/

BYTE address=0x60;
float tuned_frequency=87.61;


void tuning(float tuned_frequency)
{

 long pll;
 BYTE frequencyH,frequencyL;
 pll=(4*(tuned_frequency*1000+225))/32.768;
 printf("pll=%ld",pll);
 frequencyL=pll;
 frequencyH=pll>>8;


 i2c_start(); 
 while(i2c_write(0xc0));
 while(i2c_write(frequencyH));
 printf(" data1=%X ",frequencyH);
 while(i2c_write(FrequencyL));
 printf(" data2=%X ",frequencyL);
 while(i2c_write(0x0));
 while(i2c_write(0x10));
 while(i2c_write(0x0));
 delay_ms( 50 );
 i2c_stop();
}
 
void main (void)
{
    output_d(0x0);
   while(1)
 {
    int1 up,down;
    up=input(PIN_D0);
   if(up==1)
   {
    tuned_frequency=tuned_frequency+.20;
    printf(" Tuned Frequency=%f  ",tuned_frequency);
         output_d(0x0);
         tuning(tuned_frequency);
   }
   down=input(PIN_D1);
   if(down==1)
   {
       tuned_frequency=tuned_frequency-.20;
     printf(" Tuned Frequency=%f  ",tuned_frequency);
    output_d(0x0);
     tuning(tuned_frequency);
   }
  }

}

Slave Code:
      


#include <18F452.h>
#fuses NOWDT,NOPROTECT,NOLVP,XT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#use i2c(SLAVE, sda=PIN_B0, scl=PIN_B1, address=0x60,FORCE_HW)

BYTE datar;
BYTE dataw=0x60;

#INT_SSP
void ssp_interupt ()
{
BYTE state;


//printf("*/n");
state = i2c_isr_state(); //0 - Address match received with R/W bit clear

//1-0x7F - Master has written data; i2c_read() will immediately return the data

//0x80 - Address match received with R/W bit set; respond with i2c_write()

//0x81-0xFF - Transmission completed and acknowledged; respond with i2c_write()

if(state == 0x00)
{
datar=i2c_read();
// printf("Adress match:%x\n",datar);
datar=0x00;
}

else if(state > 0 && state < 0x80)
{
datar= i2c_read();
//printf("Bytes:%x\n",datar);
datar=0x00;
}
else if(state == 0x80)
{
i2c_write(dataw);
//printf("Data write on Master:%x\n",dataw);
}
else if(state > 0x80 && state < 0x100)
{
//printf("Data has been acknowledged\n");
}


}

void main ()
{
// port_b_pullups(TRUE);
enable_interrupts(GLOBAL);
enable_interrupts(INT_SSP);

while (TRUE) {}
}






i just try my code on proteous
at proteous the slave side is not working but at master side working correctly

please mail me ur compelete ID so i can directly take help from You Ttelmah

i try just on practly on hardware on just the Pic image circuit but it is also not working working corectly
Please help me[/img]
temtronic



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

View user's profile Send private message

PostPosted: Tue Feb 14, 2012 7:02 am     Reply with quote

I'm impessed,this is the FIRST Proteus schematic presented here WITH power going to the PIC !
Sadly it won't help in the simulation as Proteus is horrible.Full of bugs,errors, faulty DRCs,etc.
Try your code on REAL PICs,get rid of Proteus.Nobody can fix it.
With respect to component values.....use 10K instead of 47K for the MCLR resistor.Use 2K resistors for the I2C pullups( not shown but needed).The 2K used for the LEDs may be too large, 1K is better( brighter) unless you're using 'low current' LEDs.
drh



Joined: 12 Jul 2004
Posts: 192
Location: Hemet, California USA

View user's profile Send private message

PostPosted: Tue Feb 14, 2012 9:24 am     Reply with quote

Your code is setup for a 4 Mhz xtal with XT fuse.
Your schematic has a 20 Mhz xtal.
If this is correct, change your #USE DELAY(CLOCK = 4000000) to
#USE DELAY(CLOCK = 20000000) and your XT fuse to HS.
_________________
David
mateeb4u@gmail.com



Joined: 07 Feb 2012
Posts: 19
Location: pakistan

View user's profile Send private message Send e-mail Yahoo Messenger

just idea
PostPosted: Wed Feb 15, 2012 5:30 am     Reply with quote

The schematic I post of PIC controller just for idea.

At practically I'm using 4 MHz oscillator.

Request to Ttelmah reply fast and mail me ID.
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