|
|
View previous topic :: View next topic |
Author |
Message |
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
code transfer from 16F877A to 16F628A not working |
Posted: Wed Mar 22, 2006 10:03 am |
|
|
I'm working on a robot that uses an SRF08 for object detection. It uses a 16F628A on a board with little debugging capability.
I got the SRF08 working well on a 16F877A that can print output to a terminal program. However, when I transfer the program, with an *exact* copy of the i2c routine, to the 628A it appears to output values of zero. The SRF08 signals the correct device address has been reached with an LED flash. It flashes about once each second which seems correct. Also, 1.8k pull-up resistors have been installed on RA2 and RA3.
I've been working on this for two days with no progress. I've been using the head servo to try to trouble shoot the problem. I've also gone through the 628A data sheet but haven't come across anything there.
Does anyone have any other ideas I could try or some insight into what is happening?
Here is the program: Code: | #include <16F628A.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#use i2c(Master,sda=PIN_A3,scl=PIN_A2,RESTART_WDT,FORCE_HW)
#define HEAD PIN_B6
main()
{
int i;
int16 range;
setup_comparator(NC_NC_NC_NC);
while(1)
{
i2c_start(); //initate start condition
i2c_write(0xE0); //device address
i2c_write(0x00); //register address
i2c_write(0x50); //set units to inches
i2c_stop();
delay_ms(105); //wait for returning ping
i2c_start(); //initiate a new start condition
i2c_write(0xE0); //device address
i2c_write(0x02); //address of high byte register
i2c_start();
i2c_write(0xE1); //device address but read
range = i2c_read(); //read first byte
range = range << 8; // shift value left 1 byte
range += i2c_read(0); //read second byte and add to 1st
i2c_stop();
for (i=0;i<50;i++)
{
output_high(HEAD);
delay_us(1100);
delay_us(range*10);
output_low(HEAD);
delay_ms(18);
}
}
}
| Thanks, Harry |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Mar 22, 2006 10:27 am |
|
|
Quote: | #use i2c(Master,sda=PIN_A3,scl=PIN_A2,RESTART_WDT,FORCE_HW)
|
The 16F628A does not have a hardware I2C. You will need to run it in software mode. Take out the FORCE_HW and see if that works.
Ronald |
|
|
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
|
Posted: Wed Mar 22, 2006 12:02 pm |
|
|
Taking out the FORCE_HW statement didn't change anything.
BTW, I've got the sonar unit set up 24 inches from a wall so my servo should go to the 1340 position. It always goes to the 1100 position regardless of where I place an obstacle.
Thanks, Harry |
|
|
Guest
|
|
Posted: Wed Mar 22, 2006 6:05 pm |
|
|
The delay_us() function doesn't take an int16 argument, yet that is what you're trying to do....
Dan |
|
|
Harry Mueller
Joined: 17 Oct 2005 Posts: 116
|
|
Posted: Thu Mar 23, 2006 8:04 am |
|
|
Thanks Dan. I had deliberately kept the range at around 20 inches so that readings were always under 255.
However, just to make sure, I introduced a function provided by PCM_Programmer, that allows for int16 arguments in the delay_us() function. It still doesn't work correctly.
I'm still working on this, any other ideas out there?
Thanks, Harry |
|
|
|
|
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
|