|
|
View previous topic :: View next topic |
Author |
Message |
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Mar 26, 2018 12:56 am |
|
|
OK.
It's not that then.
It just seemed to be a likely cause of the behaviour.
I notice it's also setting up the comparator, so that's another thing that can be ruled out.
Agreed wholeheartedly on likely hardware issues.
That's one reason I mention the Vusb. The chips _require_ the capacitor on Vusb, even if USB is not being used, if the regulator is enabled. They can give some very odd issues if this is not present, since then the USB regulator will oscillate....
One other thought comes to mind. He talks about using a bootloader, but then posts his fuses. If the bootloader fuses do not match these, then the whole chip may not actually be configured as is being posted (since these override any fuses set in the main code). So, can you post the fuses used in the bootloader please?. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Mon Mar 26, 2018 6:54 am |
|
|
yeesh, I missed the part about using a bootloader...it'd be nice to see the whole,complete program as there could be 'something' else clobbering the EEPROM access !
It's extremely hard to debug without known all the facts so please, post your entire program. |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Wed Mar 28, 2018 9:54 am |
|
|
Ttelmah wrote: | .....The chips _require_ the capacitor on Vusb, even if USB is not being used....... So, can you post the fuses used in the bootloader please?. |
I have used a 4.7 uF cap connected to the Vusb pin. Sorry I forgot to include that in the schematic.. & I am posting the complete code below...
temtronic wrote: | yeesh, I missed the part about using a bootloader...it'd be nice to see the whole,complete program as there could be 'something' else clobbering the EEPROM access !
It's extremely hard to debug without known all the facts so please, post your entire program. |
2432.c
Code: | #ifndef EEPROM_SDA
#define EEPROM_SDA PIN_C4
#define EEPROM_SCL PIN_C3
#endif
#define hi(x) (*((int8 *)&x+1))
#use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
#define EEPROM_ADDRESS long int
#define EEPROM_SIZE 4096
void init_ext_eeprom() {
output_float(EEPROM_SCL);
output_float(EEPROM_SDA);
}
BOOLEAN ext_eeprom_ready() {
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(0xa0); // then the device is ready.
i2c_stop();
return !ack;
}
void write_ext_eeprom(long int address, BYTE data) {
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(hi(address));
i2c_write(address);
i2c_write(data);
i2c_stop();
}
BYTE read_ext_eeprom(long int address) {
BYTE data;
while(!ext_eeprom_ready());
i2c_start();
i2c_write(0xa0);
i2c_write(hi(address));
i2c_write(address);
i2c_start();
i2c_write(0xa1);
data=i2c_read(0);
i2c_stop();
return(data);
} |
Main Program:
Code: | #include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=48000000)
#include <usb_bootloader.h>
#include <lcd.c>
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#define EEPROM_SDA PIN_B0
#define EEPROM_SCL PIN_B1
#include <2432.c>
//=====================================
void main()
{
//================================
lcd_init(); // Turn LCD ON, along with other initialization commands
delay_ms(50);
lcd_gotoxy(1,1); // point LCD cursor to col1 row1
delay_ms(10);
lcd_putc("\f");
printf(lcd_putc,"EEPROM DEMO\n"); // print on LCD
delay_ms(1000);
//================================
init_ext_eeprom(); // to initialize EEPROM
output_high(PIN_B2);
write_ext_eeprom(0, 55);
delay_ms(10);
output_high(PIN_B3);
write_ext_eeprom(2, 85);
delay_ms(10);
output_high(PIN_B4);
printf(lcd_putc,"data@0 %d", read_ext_eeprom(0));
delay_ms(50);
lcd_gotoxy(9,1);
printf(lcd_putc,"data@2 %d", read_ext_eeprom(2));
delay_ms(50);
while(1);
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Mar 29, 2018 3:15 am |
|
|
What are the fuses in your bootloader?. I've asked this before.
It is better to have the main code using #fuses none, and just put the bootloader fuses as a 'remark' the line after, so you then 'know' what fuses the processor actually has. Code loaded with a bootloader can't change the fuses (if it does the bootloader will stop working...), and it is the bootloader fuses your code will be using. So show these please.
A 4.7uF electrolytic is not actually a good capacitor for the Vusb pin, unless it is a very good HF type like an OSCON capacitor. A 0.47uF polyester is the recommended type, or a 1uF electrolytic, with a 0.1uF ceramic in parallel. Bigger is not better here, it is the high frequency performance that matters. Must be 220nF min (though later application notes from MicroChip increased this to 470nF).
I'd honestly prefer to see you setting the LCD pins up yourself. However it should be using PortD on your chip by default. Presumably this is working OK?.
So what is it showing?.
Also I repeat my question about the wiring to the EEPROM?. You have to understand that the pull-up resistors have to pull the signal up in a minimum time (part of the I2C spec). Whether they can, depends on the capacitance of the I2C bus, so depends on the connections used.... |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Thu Mar 29, 2018 12:41 pm |
|
|
Ttelmah wrote: | What are the fuses in your bootloader? |
The fuses used in the bootloader is given below. as given in ex_usb_common.h
Code: | #fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN |
Ttelmah wrote: | A 4.7uF electrolytic is not actually a good capacitor for the Vusb pin, unless it is a very good HF type like an OSCON capacitor. A 0.47uF polyester is the recommended type... |
Thanks for this information,, actually my board was working ok with 4.7uf cap at the Vusb. but I will change it to 0.47uf now.
The LCD is working fine. I am getting a display 'EEPROM DEMO', but nothing else appears after this. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Mar 29, 2018 2:24 pm |
|
|
I would compile and run PCM Ps 'I2C scanner' program from the code library. It will confirm what address the EEPROM is located at, assuming you've got the correct pullup resistors, of course. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Mar 29, 2018 2:34 pm |
|
|
Try reducing the speed from 48MHz to say 8MHz. I seem to recall a possible timing issue related to I2C devices vs. compler version, maybe 3-4 months ago. You should be able to reduce PIC clock without affecting the USB clock. Others may know for sure. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Mar 30, 2018 12:47 am |
|
|
Problem is he'll have to reload the bootloader if he does this. However the easiest setting is:
Code: |
#fuses HS,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV1,VREGEN
#use_delay(clock=20MHz)
|
Which clocks the CPU off the crystal, instead of off the USB PLL. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Fri Mar 30, 2018 5:49 am |
|
|
OK.. I tried your EEPROM section of code on an 18F46K22 and it works 100% even at 64MHz. I made minor changes to show sent and received data from EEPROM, looping from 32 to 255.
Code: |
//================================
init_ext_eeprom(); // to initialize EEPROM
for(data=32;data<255;data++){ //loop printable character
output_high(PIN_B2);
write_ext_eeprom(0, data);
lcd_gotoxy(1,1);
printf(lcd_putc,"sent %d",data); //show what was sent to loc 0
delay_ms(10);
output_high(PIN_B3);
write_ext_eeprom(2, data+1);
lcd_gotoxy(1,3);
printf(lcd_putc,"sent %d",data+1); //show what was sent loc 2
delay_ms(10);
output_high(PIN_B4);
lcd_gotoxy(11,1);
printf(lcd_putc,"rcvd %d", read_ext_eeprom(0)); //dsp eeprom 0
delay_ms(50);
lcd_gotoxy(11,3);
printf(lcd_putc,"rcvd %d", read_ext_eeprom(2)); //dsp eeprom 2
delay_ms(50);
delay_ms(1000); //wait 1 sec to see data
} //end of for loop //forever loop( 32 to 255 )
|
Since your program 'stops or stalls', I'm thinking the EEPROM is not connected properly. |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Sun Apr 01, 2018 9:19 am |
|
|
temtronic wrote: | OK.. I tried your EEPROM section of code on an 18F46K22 and it works 100% even at 64MHz..... Since your program 'stops or stalls', I'm thinking the EEPROM is not connected properly. |
What value of pullup resistors you have used ? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Sun Apr 01, 2018 11:31 am |
|
|
4K7 as I'm using a VDD of 5V and close to the PIC.
Jay |
|
|
SubhamayS
Joined: 07 Mar 2012 Posts: 34 Location: jalpaiguri, India
|
|
Posted: Mon Feb 17, 2020 10:25 am |
|
|
Ttelmah wrote: |
A 4.7uF electrolytic is not actually a good capacitor for the Vusb pin, unless it is a very good HF type like an OSCON capacitor. A 0.47uF polyester is the recommended type, or a 1uF electrolytic, with a 0.1uF ceramic in parallel. Bigger is not better here, it is the high frequency performance that matters. Must be 220nF min (though later application notes from MicroChip increased this to 470nF). |
Just wanted to verify my design... as per your suggestion I am changing the capacitor at Vusb pin to 470 nF. But which type should I use.. !! electrolytic or ceramic ???? please suggest.... Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Mon Feb 17, 2020 10:40 am |
|
|
Multilayer ceramic.
You want a really low ESR & good HF response.
The alternative quite a few people use is a 1uF electrolytic, in parallel with
a 0.1uF ceramic. This boosts the HF response that electrolytics tend to
lack. |
|
|
|
|
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
|