|
|
View previous topic :: View next topic |
Author |
Message |
mojsa2000
Joined: 18 May 2010 Posts: 78
|
problem with 16f887a and ds1307 |
Posted: Wed Dec 29, 2010 8:03 am |
|
|
Hi
I've made a prototype board. on the board I have a pic16f887a & a ds1307 & a 24c512 (I2C eeprom). In this project I read
2 analog values and display them on lcd (16*2). I've made 2 programs. First is simple and it read analog inputs and
displays them on lcd. It works correctly. Second program is included ds1307 and eeprom. When I turn it on, I see black
squares on lcd. I am sure that the lcd is connected correctly because it works with first program.
I can't understand why this occurs. Please help me. (I'm sure the hardware has problem) |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Dec 29, 2010 8:19 am |
|
|
First, do you have the correct value for the I2C bus pullup resistors installed?
Second, are you using the PICs I2C bus, or other pins?
Third, post a small, compilable program that includes .H files,#fuses and the version of your compiler.
Fourth, try just adding say the RTC chip and code to your working program, debug until it works, then add the EEPROM chip and code. |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Wed Dec 29, 2010 8:52 am |
|
|
Thanks
But its necessary to say that previous board that I made works with this program. Then I decided to modify the board area and resized it. But I
didn't change any part of board. But with the same elements, it doesn't
work. I can't recognize it and I'm confused. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Dec 29, 2010 9:09 am |
|
|
Sounds like it's time to 'ring out' the board.
Print a copy of the schematic, and get a highlighter felt pen and an ohmeter with buzzer.
Pick a trace on the schematic and confirm with the ohmeter that the writing is correct. If correct, highlight that trace on the schematic to say it's OK.
Repeat for ALL the traces...
Odds are when you 'resized' and modified the board, some traces were either reversed, crossed, not connected or shorted.
This proceedure works best with NO components soldered in(easier) but works with complete boards.
A board with just a PIC and a few components might take an hour or so to check..... |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Wed Dec 29, 2010 11:18 am |
|
|
hi again
I'm so confused. why not? I made simple programs with pic & ds1307 and pic & 24c512 and pic & ds1307 & 24c512.
These programs are so simple. I checked all of them on my board. All of them worked on the last board. But the main version didn't work again. I tried on previous board and the main version worked.
Why?
why this occur?
The main program occupy 99% of ROM and 64-78% of RAM.
Please help me. it made me dizzy!!! |
|
|
gpsmikey
Joined: 16 Nov 2010 Posts: 588 Location: Kirkland, WA
|
|
Posted: Wed Dec 29, 2010 11:36 am |
|
|
If you made any change to the board, then there is probably a missed connection somewhere. If it is the same artwork for the board, but this one does not work and the previous one did, "ring it out" as suggested. Be sure and check for incomplete etching on the board that leaves a jumper between traces. I had one some years ago that took a while to find - an internal void in the board allowed the "thru-hole plating" to jumper several pins together INSIDE the board. If it worked on one, but does not on the new version, SOMETHING is different.
You don't say what you are using to program the chip, but if you are using ISP with something like the PICkit2, don't rule out the handy feature that is part of the stand alone version of the software - the Uart Tool. You can set up a simple software uart to send status and other information to the Uart Tool via the ISP connector so you know just what is going on in the code.
mikey _________________ mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3 |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Wed Dec 29, 2010 3:49 pm |
|
|
Hi again
I did what you'd said but the problem didn't get solved. But there was a funny note. I've used #rs232 in my program.
The program, by a FT232rl, makes a connection between the board and the PC via a COM port. When I connected the usb connector to my board and reset it, the black squares problem is solved. But when I disconnect the usb connector my program hangs on (stops but there aren't black squares).
I don't want to connect the usb connector to the board all of the time. I need it when I want to read the data from eeprom.
I use rs232 option as below:
Code: | #use delay (clock=4000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
Also, I use RDA int. & kbhit() function in the program. Does everyone know why the error takes place? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Dec 29, 2010 4:28 pm |
|
|
Your DC power connector may not have a good ground connection and
the USB connector provides the ground.
Look for bad wire connections, or PCB connections, including solder joints.
Or it may be missing from your design. |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Thu Dec 30, 2010 3:50 am |
|
|
dear pcm programmer
I checked all of connections in the board by the protel dxp and then on the board. There is not any bad connection.
I rang some parts out and it didn't change. Is it related to rs232 setting option? I'm so bored and confused. It's vital to find the problem but I can't. I place main code there. Please review it and help me.
Code: |
#include <16f877a.h>
#FUSES XT,NOWDT,PUT,BROWNOUT,NOLVP
#DEVICE ADC=10
#use delay (clock=4000000)
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include <H:\PIC\My sources\ds1307.c>
#include <H:\PIC\My sources\24c512.c>
#include <H:\PIC\My sources\memory_pointers_maker.c>
#include <H:\PIC\My sources\flex_lcd.c>
#include <H:\PIC\My sources\data_sending.c>
#include <H:\PIC\My sources\communication.c>
#define saved_pos_energy 65516
#define saved_neg_energy 65520
#define saved_coef1 65524
#define saved_coef2 65528
#define saved_coef3 65532
static float energy,total_energy;
static float v_out,i_out;
//static float hourly_v=0,hourly_i=0;
//static float daily_v=0,daily_i=0;
static float hourly_positive_power=0,hourly_negative_power=0;
static float daily_positive_power,daily_negative_power;
static float hourly_Energy=0;
float daily_Energy=0;
float time_coeff=1;
float v_buffer,i_buffer;
float v_dc,i_dc;
unsigned int channel=0;
static int counter=0;
int8 tzone11,tzone12,tzone21,tzone22,tzone31,tzone32;
static float tcoe13,tcoe23,tcoe33;
float time_coeff1,time_coeff2,time_coeff3;
static float pos_total_display,neg_total_display;
static float show_pos_total_display,show_neg_total_display;
//********************* All flags *******************************************
int1 half_min_flag;//a flag for checking that 30 seconds are passed
int1 one_min_flag;
int1 ten_sec_flag;
int1 ten_min_write_to_eeprom;
int1 hour_write_to_eeprom;
int1 day_write_to_eeprom;
int1 first_time_flag_check=0;
int1 first_time_flag_check_for_hour=0;
int1 first_time_flag_check_for_day=0;
int1 calculating_flag,data_sending_flag;
int1 erase_cmd_flag;
int1 v_sign,i_sign;
int1 pc_date_set,pc_time_set;
int1 display_lcd_flag=1;
int1 save_coef_flag=0;
//*****************************************************************************
unsigned int8 half_min_counter=0;
unsigned int8 one_min_counter=0;
unsigned int16 v_memory_pointer,i_memory_pointer;
unsigned int16 hourly_pos_VI_memory_pointer,hourly_neg_VI_memory_pointer;
unsigned int16 daily_pos_VI_memory_pointer,daily_neg_VI_memory_pointer;
char c1[20],c2[20],c3[20];
//**************** setting up ds1307 ******************
//*****************************************************
int8 sec;
int8 min;
int8 hour;
int8 day;
int8 month;
int8 year;
int8 dow;
int8 ten_sec_counter;
//************************************
#int_AD
void AD_isr(void)
{
counter++;
if(counter==2){
if(i_sign)//read channel(0)_reserved for voltage
{
i_buffer=read_adc(ADC_READ_ONLY);;
i_sign=0;
channel=1;
}
}
if(counter==4){
if(v_sign)//read channel(1)__reserved for current
{
v_buffer=read_adc(ADC_READ_ONLY);;
v_sign=0;
calculating_flag=1;
counter=0;
channel=0;
}
}
}
//********************************************
#int_TIMER2
void TIMER2_isr(void)
{
if(channel==0)
{
set_adc_channel(0);
i_sign=1;
}
else
{
set_adc_channel(1);
v_sign=1;
}
read_adc(ADC_start_ONLY);
}
//**************************************************************
//************** Recieve Data_RS232 INT START ***************
//**************************************************************
#int_RDA
void RDA_isr(void)
{
if (kbhit())
{
check_status();
timezone();
dateset();
timeset();
ata_read();
}
}
//**************************************************************
//************************* RTCC INT START ******************
//**************************************************************
#int_RTCC
void RTCC_isr(void)
{
half_min_counter++;
one_min_counter++;
ten_sec_counter++;
if ((min==0) || (min==10) ||(min==20) ||(min==30) ||(min==40) ||(min==50) )
{//check per 10 mins in RTCC int
if(!first_time_flag_check)
{
ten_min_write_to_eeprom=1;
first_time_flag_check=1;
break;
}
}
else
first_time_flag_check=0;
//**************************************
if (min==0)
{
if(!first_time_flag_check_for_hour)
{
hour_write_to_eeprom=1;
first_time_flag_check_for_hour=1;
}
}
else
first_time_flag_check_for_hour=0;
//****************************************
if(hour==0)
{
if(!first_time_flag_check_for_day)
{
day_write_to_eeprom=1;
first_time_flag_check_for_day=1;
}
}
else
first_time_flag_check_for_hour=0;
//****************************************
if(half_min_counter==30)
{
half_min_flag=1;
half_min_counter=0;
}
if(one_min_counter==60)
{
one_min_flag=1;
one_min_counter=0;
}
if(ten_sec_counter==10){
ten_sec_counter=0;
ten_sec_flag=1;
display_lcd_flag=1;}
}
//*****************************************************
//******************** RTCC INT END *******************
//*****************************************************
float read_hourly_vi(int8 hour,int8 day)
{
hourly_pos_VI_memory_pointer_func(hour,day);
hourly_positive_power=eeprom_read(hourly_pos_VI_memory_pointer);
hourly_neg_VI_memory_pointer_func(hour,day);
hourly_negative_power=eeprom_read(hourly_neg_VI_memory_pointer);
return hourly_positive_power ,hourly_negative_power;
}
float read_daily_vi(int8 day)
{
daily_pos_VI_memory_pointer_func(day);
daily_positive_power=eeprom_read(daily_pos_VI_memory_pointer);
daily_neg_VI_memory_pointer_func(day);
daily_negative_power=eeprom_read(daily_neg_VI_memory_pointer);
return daily_positive_power,daily_negative_power;
}
//********************************************
void calculating()
{
if((hour>=tzone11)&(hour<=tzone12)){
//time_coeff=tcoe13;
time_coeff=time_coeff1;
}
else if((hour>=tzone21)&(hour<=tzone22)){
//time_coeff=tcoe23;
time_coeff=time_coeff2;
}
else if((hour>=tzone31)&(hour<=tzone32)){
//time_coeff=tcoe33;
time_coeff=time_coeff3;
}
if(calculating_flag)
{
v_dc=v_buffer*5/1023;
i_dc=i_buffer*5/1023;
//******************************
//b:
v_out = (8.3333 * v_dc ) + 36.6666;
i_out = (50 * i_dc) - 125;
energy=time_coeff *v_out*i_out*0.004; //calculates the energy in per 8ms
total_energy+=energy;
}
calculating_flag=0;
}
void settings(){
if(save_coef_flag){
time_coeff1=atof(c1);
time_coeff2=atof(c2);
time_coeff3=atof(c3);
eeprom_write(time_coeff1,saved_coef1);
delay_ms(10);
eeprom_write(time_coeff2,saved_coef2);
delay_ms(10);
eeprom_write(time_coeff3,saved_coef3);
delay_ms(10);
save_coef_flag=0;
}
if(pc_time_set)
{
ds1307_set_time(hour,min,sec);
pc_time_set=0;
};
if(pc_date_set)
{
ds1307_set_date(day,month,year);
pc_date_set=0;
};
}
//*****************************************
//*******************************************
//*******************************************
void main()
{
//SET_TRIS_A( 0xFF );
enable_interrupts(INT_AD);
enable_interrupts(INT_EXT);
enable_interrupts(INT_RTCC);
setup_adc_ports(AN0_AN1_VSS_VREF);
setup_adc(ADC_CLOCK_DIV_8);
enable_interrupts(INT_RDA);
setup_timer_2(T2_DIV_BY_1,255,4);//per 1ms
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
setup_comparator(NC_NC_NC_NC);
ext_int_edge( H_TO_L );
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
setup_timer_0(RTCC_EXT_H_TO_L|RTCC_DIV_32);
set_timer0(0);
set_timer2(0);
ds1307_init();
delay_ms(50);
lcd_init();
delay_ms(50);
pos_total_display=eeprom_read(saved_pos_energy);
neg_total_display=eeprom_read(saved_neg_energy);
time_coeff1=eeprom_read(saved_coef1);
time_coeff2=eeprom_read(saved_coef2);
time_coeff3=eeprom_read(saved_coef3);
clock_output();
while(1)
{
if(data_sending_flag)
{
data_sending();
data_sending_flag=0;
}
calculating();
settings();
if(half_min_flag)
{
calculating();
settings();
//**********************
if (ten_min_write_to_eeprom)
{
v_memory_pointer_func(hour,min,day);
i_memory_pointer_func(hour,min,day);
eeprom_write(i_out,i_memory_pointer);
eeprom_write(v_out,v_memory_pointer);
if(energy>=0){
pos_total_display+=energy;
eeprom_write(pos_total_display,saved_pos_energy);
show_pos_total_display=pos_total_display/3600000;
}
if(energy<0){
neg_total_display+=energy;
eeprom_write(neg_total_display,saved_neg_energy);
show_neg_total_display=neg_total_display/3600000;
}
ten_min_write_to_eeprom=0;
//********************************
if(hour_write_to_eeprom)
{
hourly_Energy=total_energy/3600;
daily_Energy+=hourly_Energy;
hourly_pos_VI_memory_pointer_func(hour,day);
hourly_neg_VI_memory_pointer_func(hour,day);
if(hourly_Energy>=0)
{
//pos_total_display+=hourly_Energy;
eeprom_write(hourly_Energy,hourly_pos_VI_memory_pointer);
eeprom_write(0,hourly_neg_VI_memory_pointer);
}
if(hourly_Energy<0)
{
//neg_total_display+=hourly_Energy;
eeprom_write(hourly_Energy,hourly_neg_VI_memory_pointer);
eeprom_write(0,hourly_pos_VI_memory_pointer);
}
hour_write_to_eeprom=0;
}
//******************************************************************
if(day_write_to_eeprom)
{
if(daily_Energy>=0)
{
daily_pos_VI_memory_pointer_func(day);
eeprom_write(daily_Energy,hourly_pos_VI_memory_pointer);
eeprom_write(0,hourly_neg_VI_memory_pointer);
}
if(daily_Energy<0)
{
daily_neg_VI_memory_pointer_func(day);
eeprom_write(daily_Energy,hourly_neg_VI_memory_pointer);
eeprom_write(0,hourly_pos_VI_memory_pointer);
}
day_write_to_eeprom=0;
daily_Energy=0;
}
}
half_min_flag=0;
}
calculating();
if(display_lcd_flag)//display the values On LCD in per minute
{
settings();
lcd_clear();
lcd_gotoxy(1,1);
ds1307_get_time(hour,min,sec);
ds1307_get_date(day,month,year,dow);
printf(lcd_putc,"20%u/%u/%u,%02u:%02u",year,month,day,hour,min);
lcd_gotoxy(1,2);
printf(lcd_putc,"v=%.1f,i=%.1f",v_out,i_out);
delay_ms(5000);
read_hourly_vi(hour,day);
read_daily_vi(day);
lcd_clear();
lcd_gotoxy(1,1);
printf(lcd_putc,"+E=%.1f",show_pos_total_display);
lcd_gotoxy(1,2);
printf(lcd_putc,"-E=%.1f",show_neg_total_display);
one_min_flag=0;
display_lcd_flag=0;
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Thu Dec 30, 2010 4:11 am |
|
|
Think about it. You know the PIC is running, and the LCD. You have added routines that use I2C, and the unit hangs. Reasons for I2C hanging, are:
1) Lines not pulled up correctly.
2) Line held low (whisker in board?).
3) Connection error.
4) Device on bus not powered.
Now there is no point in posting code - you know this worked with your old board. So, you need to be doing hardware debugging. You need to test that the I2C connections _do_ really go exactly where they went on the old board, that there really is a supply on the pins where it should be, that the lines do pull up to 5v. etc..
Write a simple 'couple of liner', that just puts a square wave onto the first I2C wire. Test with a scope that this does go up and down, does go to the I2C devices. Do the same with the other I2C line. Also check that nothing else is going up and down with these pins...
You need to do some simple hardware debugging.
Best Wishes |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
|
Posted: Tue Jan 04, 2011 3:31 am |
|
|
Hi
I found the main problem. The problem is related to rs232. When I disabled the RDA int, the problem was solved. I can't understand why it takes place.
I think a noise makes a RDA INT service always. How can I control the receiving data on FT232RL to omit undesirable noise?
best regards |
|
|
mojsa2000
Joined: 18 May 2010 Posts: 78
|
problem solved |
Posted: Tue Jan 04, 2011 1:54 pm |
|
|
Hi
Thanks guys. The problem almost has solved. The main problem was related to a noise. Because I used RDA int and the RX pin affected by noise and maked a INT. I pulled up the RX pin with a 3K3 ohm resistor and any noise was bypassed. Now my board connects to PC.
But I have a small problem. The sent data that is received in pc is not exactly correct. I think it's related to noise again. I'll try to omit it and report the results as soon possible. |
|
|
|
|
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
|