View previous topic :: View next topic |
Author |
Message |
perthcom
Joined: 10 Jun 2005 Posts: 10
|
Migrating from F873 to F876A issues, yes i searched |
Posted: Wed Oct 24, 2007 6:15 am |
|
|
Hi all
I have working code under F873 that I want to migrate to F876A so I can expand the program. The circuit uses a Mx-com chip that I had made functions to load and read (sorta I2C protcol). These functions do not work with the F876A.
I've read MicroChip's migration data on this chip and I see no reason why it will not work. I'm using version 3.225 compiler.
The rest of the program seems to run, reading and writing to EEPROM, lost of printf's. RS232 is working fine.
Basically i just clock in the data in and out of the chip in my functions. Is there something with the SHIFT() function that does not work?
Here is my code to load the data. I'm using TRIS to set the I/O and manipulate the I/O bits directly, not sure if this is my issue, but hard to teach this old dog new tricks. I've been playing with the timing as well with no luck
toggle_clock()
{
delay_us(100);
clk = 1;
delay_us(100);
clk = 0;
delay_us(100);
}
write_tbus(highbyte,lowbyte)
{
int buffer[2];
buffer[1] =highbyte;
buffer[0] = lowbyte;
clk = 0;
delay_ms(1);
for(i=1; i<17; ++i)
{
IF(shift_right(buffer,2,1))
{
command_data = 1;
}
ELSE
{
command_data = 0;
}
toggle_clock();
}
delay_ms(1);
latch = 1;
delay_ms(1);
latch = 0;
}
any help is appreciated |
|
|
Ttelmah Guest
|
|
Posted: Wed Oct 24, 2007 6:53 am |
|
|
The obvious thing you don't mention, is _what pins_ clock, command_data, and latch are mapped to.
Remember that you need to turn off the comparator, or some pins (RA4, and RA5 in particular), may default to the comparator operation in the larger chip.
Best Wishes |
|
|
perthcom
Joined: 10 Jun 2005 Posts: 10
|
|
Posted: Wed Oct 24, 2007 7:29 am |
|
|
I was going by the Migration sheet put out by Microchip where it says "The comparator is DISABLED on power-up so that existing PIC16F87x code requires no modifications" I put in code to be sure the comparator is Disabled, but still no luck :(
I am using Port A pins for my Data, Clock and Latch pins. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Wed Oct 24, 2007 8:11 am |
|
|
Indeed of the Program Memory, RAM and EEPROM size improvements, the main
difference between both MCU´s is the Analog Comparator capabilities added in
the 16F876A.
As Ttelmah said, you must switch off such module which share some pins of PortA.
Code: |
void main()
{
...........
...........
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
...........
...........
}
|
Humberto |
|
|
perthcom
Joined: 10 Jun 2005 Posts: 10
|
|
Posted: Wed Oct 24, 2007 8:35 am |
|
|
I have one analogue on A0, the rest is all fixed I or O. here is my setup.
Code: |
void main()
{
int cntr, command, temp, timer;
int command1,timer_toneA;
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_adc_ports(RA0_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_spi(FALSE);
setup_counters(RTCC_INTERNAL,WDT_2304MS);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(ccp_off);
setup_ccp2(ccp_off);
SET_TRIS_A(0b00010001);
SET_TRIS_B(0b01001111);
SET_TRIS_C(0b10000000);
control_port = 0b00000101;
...
... etc
|
|
|
|
Ttelmah Guest
|
|
Posted: Wed Oct 24, 2007 8:50 am |
|
|
I'd try manually defining the comparator configuration register, and writing the value to turn it off yourself. Unfortunately, some of the older compilers don't set the values correctly on some chips, and yours might be one with this problem.
As a separate 'comment', 'ADC_CLOCK_INTERNAL', is _not_ reliable for getting accurate ADC conversions, unless you use sleep mode to stop the chip while the conversion is performed. Use one of the forms synchronised to the master clock instead (the divisor required will depend on your clock rate). This can easily give another couple of bits of effective accuracy on the ADC.....
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 24, 2007 10:59 am |
|
|
You need to post a small test program that shows the problem.
Suppose you have determined that the clock signal is not working
by looking at it with an oscilloscope. Then create a small test
program like the one shown below, test it, confirm that it fails,
and then post it.
The program must be complete, and it must compile without errors.
If you can do that, we might be able to solve the problem.
Code: |
#include <16F876A.h>
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#bit clk = 5.0
toggle_clock()
{
delay_us(100);
clk = 1;
delay_us(100);
clk = 0;
delay_us(100);
}
//======================
void main()
{
toggle_clock();
while(1);
} |
|
|
|
Guest
|
|
Posted: Wed Oct 24, 2007 2:18 pm |
|
|
I have checked with a 'scope, i have clock and data signals coming from the PIC, but the timing of them is not exactly the same as with the working F873.
I don't have a storage scope to get a good look at it, but i would say the clock is slower on the F876A. I checked the crystal Osc. frequency with both chips and its bang on.
The exact frequency of the clock should not matter as I assert the data bit, then toggle the clock and on to the next data bit. I'm not running the bleeding edge of speed either.
maybe a bug in the compiler and i just need to upgrade? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 24, 2007 2:59 pm |
|
|
The delay_ms() routine for the 16F876A uses a smaller loop count value
than the 16F873. It uses 37 instead of 42. The rest of the delay_ms
code is the same except for a different temp variable. So the "1 ms"
delay for the 16F876A will be shorter. Possibly, that might have some
effect on your program.
Quote: |
16F876A --
0013: MOVLW 25 // 37 decimal
0014: MOVWF 04
0015: MOVF 00,W
0016: BTFSC 03.2
0017: GOTO 027
0018: MOVLW 01
0019: MOVWF 78
001A: CLRF 77
001B: DECFSZ 77,F
001C: GOTO 01B
001D: DECFSZ 78,F
001E: GOTO 01A
001F: MOVLW 4A
0020: MOVWF 77
0021: DECFSZ 77,F
0022: GOTO 021
0023: NOP
0024: NOP
0025: DECFSZ 00,F
0026: GOTO 018 |
Quote: |
16F873 --
0013: MOVLW 2A // 42 decimal
0014: MOVWF 04
0015: MOVF 00,W
0016: BTFSC 03.2
0017: GOTO 027
0018: MOVLW 01
0019: MOVWF 21
001A: CLRF 20
001B: DECFSZ 20,F
001C: GOTO 01B
001D: DECFSZ 21,F
001E: GOTO 01A
001F: MOVLW 4A
0020: MOVWF 20
0021: DECFSZ 20,F
0022: GOTO 021
0023: NOP
0024: NOP
0025: DECFSZ 00,F
0026: GOTO 018
0027: RETLW 00 |
|
|
|
perthcom
Joined: 10 Jun 2005 Posts: 10
|
|
Posted: Thu Oct 25, 2007 7:21 am |
|
|
I've purchased the latest version of the compiler so I'll see if that fixes it.
By trimming my printf's i've got it into a F873 with 99% program memory usage.. seems to check out so far so i have some breathing room to get the bugs out of the F876A
thanks for you help!
|
|
|
perthcom
Joined: 10 Jun 2005 Posts: 10
|
|
Posted: Tue Oct 30, 2007 6:05 pm |
|
|
Well new compiler did not fix the problem.
Everything in my code seems to work properly it seems like it just won't write data (2 bytes) into a peripheral chip.
So I compared the C/ASM code from both the working 16F873 and the 16F876A (Same C program with 2 lines of code added to turn off comparators) and the compiler generates exactly the same code, right down to the GOTO addresses.
When I scope the DATA and Clock the pulse time looks different (no storage scope to really analyze)
I'm baffled.
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Oct 30, 2007 7:27 pm |
|
|
Quote: | The circuit uses a Mx-com chip. |
Post a link to the data sheet for this chip. |
|
|
|