|
|
View previous topic :: View next topic |
Author |
Message |
vinu Guest
|
error in PIC16F690 code |
Posted: Thu Aug 24, 2006 2:22 am |
|
|
Dear Sir,
See the below code in CCS C compliler
#include <16f690.h>
#fuses NOWDT,INTRC_io,BROWNOUT,PUT,NOPROTECT,NOIESO,NOFCMEN,noMCLR
#use delay (clock=4000000)
main()
{
set_tris_c(0x00);
set_tris_a(0xff);
output_low(PIN_c3);
output_low(PIN_c6);
output_low(PIN_c7);
delay_ms(2000);
output_high(PIN_c3);
output_high(PIN_c6);
output_high(PIN_c7);
while(1);
}
Expected output PORTC 3,6,7 shows five volt.
But the code not work well in target board. pin c3 shows zero volt
But when i slightly changes the code all are working well. only thing i do is changes the order in which out pins are turns on . ie pinc6 first and then pin c3. now all the output pins shows five volt output. Find it very curious. Any one know the answer?. When i write a code in assembly (MPASM) language and tested it in the same target board no prblem occurs.
main()
{
set_tris_c(0x00);
set_tris_a(0xff);
output_low(PIN_c3);
output_low(PIN_c6);
output_low(PIN_c7);
delay_ms(2000);
output_high(PIN_c6);
output_high(PIN_c3);
output_high(PIN_c7);
while(1);
} |
|
|
Ttelmah Guest
|
|
Posted: Thu Aug 24, 2006 3:43 am |
|
|
This is not a CCS problem, but the PIC 'RMW' problem.
When you modify a single pin on the port like this, the processor performs a whole series of operations in the single instruction cycle:
Read the value currently on the port pins.
Set/reset the requested bit.
Output this modified value to the port pins.
Now the problem is that if you perform two such operations 'one after the other', and there is a capacitive load on the pin, the following happens:
1 Read the value currently on the port pins.
2 Set/reset the requested bit.
3 Output this modified value to the port pins.
4 Pin starts charging towards the requested voltage.
5 Read the value currently on the port pins.
6 Set/reset the requested bit.
7 Output this modified value to the port pins.
Unfortunately, because of the time taken for the capacitive load to charge, when the code reaches step '5', the pin that has just been set/reset, still _reads_as being at it's 'old' value. It is then read with the wrong value, and is output at the end of the second instruction, with this wrong value, and the 'setting' is lost....
Hence, when dealing with loaded pins, there are two options to you. The first, is to hold a local 'copy' of the value you expect to be on the port, update the bits on this, and output the whole of this to the port. The second choice is to allow a pause after writing a pin, to ensure that the voltage has time to settle. On the '18' chips, there is a third option, in that the output latch register on these is directly readable (on the 16 chips, this is not the case), so you can read the bits on the output latch, rather than the states of the pins themselves.
Best Wishes |
|
|
vinu Guest
|
pic 16f690 error |
Posted: Thu Aug 24, 2006 5:50 am |
|
|
Dear Sir,
Thanks for your replay.I tried with following code. But the problem again persists.
main()
{
set_tris_c(0x00);
set_tris_a(0xff);
output_high(PIN_c3);
delay_ms(2000);
output_high(PIN_c6);
delay_ms(2000);
output_high(PIN_c7);
delay_ms(2000);
output_low(PIN_c3);
delay_ms(2000);
output_low(PIN_c6);
delay_ms(2000);
output_low(PIN_c7);
delay_ms(2000);
while(1);
}
regards,
Vineesh.A |
|
|
drh
Joined: 12 Jul 2004 Posts: 192 Location: Hemet, California USA
|
|
Posted: Thu Aug 24, 2006 7:16 am |
|
|
You probably need to disable the comparator. The datasheet for the 16F690 shows how to do this. _________________ David |
|
|
vinu Guest
|
pic16f690 error code |
Posted: Sun Aug 27, 2006 11:40 pm |
|
|
sir,
is there any specific instruction in CCSC to disable comparator. any one give an example?
Regards,
Vinu |
|
|
Ttelmah Guest
|
|
Posted: Mon Aug 28, 2006 2:21 am |
|
|
setup_comparator(NC_NC_NC_NC);
Best Wishes |
|
|
vinu Guest
|
error in PIC16F690 code |
Posted: Tue Aug 29, 2006 12:41 am |
|
|
Thanks everyone
problem is solved
regards,
vinu |
|
|
|
|
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
|