CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Again RA4

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Max



Joined: 15 Dec 2003
Posts: 51
Location: Italy

View user's profile Send private message

Again RA4
PostPosted: Thu Apr 22, 2004 1:50 am     Reply with quote

use PIC16LF628A VDD 3V.
RA0,RA1,RA2,RA3,RA4.RA7 through R 220 ohm and led is connected
at VDD

RAx -------R 220ohm ------ LED ------- VDD

RA4 it creates problems, led remains always on (ra4 is 0)
the PIC16LF628A it is not broken, tried others

#use FAST_IO(A)
#use FAST_IO(B)

setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

#byte PORTA = 0X05
#byte PORTB = 0X06
#byte TRISA = 0x85
#byte TRISB = 0X86


#define LED5 PORTA,0
#define LED4 PORTA,1
#define LED3 PORTA,2
#define LED2 PORTA,3
#define LED1 PORTA,4
#define LED6 PORTA,7

set_tris_B(0b11111111);
set_tris_A(0b00000000);
bit_set(LED1);
bit_set(LED2);
bit_set(LED3);
bit_set(LED4);
bit_set(LED5);
bit_set(LED6);


while (TRUE)
{
bit_clear(LED1); // is connected RA4
...................... // waith press button

bit_set(LED1); // not OFF ????????????????? Help my
bit_clear(LED2);
...................... // waith press button
.......................
....................
bit_set(LED6);
}

Thanks
Ttelmah
Guest







Re: Again RA4
PostPosted: Thu Apr 22, 2004 2:33 am     Reply with quote

Max wrote:
use PIC16LF628A VDD 3V.
RA0,RA1,RA2,RA3,RA4.RA7 through R 220 ohm and led is connected
at VDD

RAx -------R 220ohm ------ LED ------- VDD

RA4 it creates problems, led remains always on (ra4 is 0)
the PIC16LF628A it is not broken, tried others

#use FAST_IO(A)
#use FAST_IO(B)

setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

#byte PORTA = 0X05
#byte PORTB = 0X06
#byte TRISA = 0x85
#byte TRISB = 0X86


#define LED5 PORTA,0
#define LED4 PORTA,1
#define LED3 PORTA,2
#define LED2 PORTA,3
#define LED1 PORTA,4
#define LED6 PORTA,7

set_tris_B(0b11111111);
set_tris_A(0b00000000);
bit_set(LED1);
bit_set(LED2);
bit_set(LED3);
bit_set(LED4);
bit_set(LED5);
bit_set(LED6);


while (TRUE)
{
bit_clear(LED1); // is connected RA4
...................... // waith press button

bit_set(LED1); // not OFF ????????????????? Help my
bit_clear(LED2);
...................... // waith press button
.......................
....................
bit_set(LED6);
}

Thanks

Your code does not show what your problem is...
In two successive lines, you clear the LED, and then set it on again. You will never see an 'off' that it this short.
However I'd expect that your problem is at heart the 'read modify write' problem associated with ports. RA4, is different from the rest of the port a pins, in two ways. First, it is an 'open collector' (pull down only) output, but it also has Schmidt trigger input levels. Now it is important to understand, that when you do a bit 'clear' or set on an output port, you do _not_ just access this bit. In fact the processor, reads the whole port, modifies the specified bit, and then writes the result back to the output. So when you 'bit_clear' RA4, the status of the other pins, becomes the value read' from them. If you code as (for instance):

bit_clear(LED4);
bit_set(LED2);

Then the whole port is read, and bit four is cleared. This value is then written to the port, and the port read again, and bit 2 is set. If at this instant in time, RA4, _has not yet reached the 'low' value_, the 'read' will return it a 'high', and this is the value written back to the register.
The same applies in the other direction (setting the bit).
Since the physical 'write' takes place at the 'end' of the first instruction, while the 'read' takes place at the start of the second, it does not take much load to prevent the signal from having reached it's selected level.
Hence it is allways better to code in one of two ways. Either save a byte that you call 'port_b_output', and set/clear the bits on this, then write the whole byte in one I/O operation, or code as:
bit_clear(LED4);
delay_us(1);
bit_set(LED2);

with the time delay made long enough to allow the pin to reach the level.
Now the problem in the case of RA4 however is made worse when 'setting', because you don't have an adequate 'pull up', and the pin will never reliably reach the 'high' level!.
The reason is that the 'high' input threshold on a Schmidt input, is 0.8Vdd. So the pin needs to be pulled up to 2.4v, to 'read' as being high.
Unfortunately, the voltage drop associated with the LED, is enough to ensure this will probably never happen. So wire as:

RA4----+---220R-----LED----+----Vdd
+---------10KR-------+

This then ensures that the pin will actually pull up to the high level when turned off. The other inputs only have to pull up to 1.55v, to be seen as 'high', and are not dependant on the resistor to actually pull them up. The switching speed of the driver transistors is fast enough that you are not seeing the problem on the other pins.
Do a search on the MicroChip website, on the words 'Read Modify Write', you will find a lot of notes about this.

Best Wishes
Max



Joined: 15 Dec 2003
Posts: 51
Location: Italy

View user's profile Send private message

PostPosted: Thu Apr 22, 2004 3:35 am     Reply with quote

Thanks for your fast reply.

I don't think that the problem is on 'Read Modify Write' becose I've insert resistor from RA4 and VDD ( 4k7 ) but the led RA4 is always on (RA4=0).
I've put delay in this way :

delay_us(2);
bit_set(LED1);
delay_us(2);
bit_set(LED2);
delay_us(2);
bit_set(LED3);
delay_us(2);
bit_set(LED4);
delay_us(2);
bit_set(LED5);
delay_us(2);
bit_set(LED6);
but LED1 ( Pin RA4) still always on.
Seems to me to put in off comparator with those instruction:

setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

but no result....Why?
Probabli is better to abbandon PIN RA4 and take PIN RA6 ....!!!!

Let me know
Lorenzo
Guest







PostPosted: Thu Apr 22, 2004 3:56 am     Reply with quote

RA4 is an open drain output type and therefore it has a negated logic.
Set_bit(LED1) turn on the led,
clear_bit(LED1) turn off the led.

Good luck
Max



Joined: 15 Dec 2003
Posts: 51
Location: Italy

View user's profile Send private message

PostPosted: Thu Apr 22, 2004 6:27 am     Reply with quote

It is not possible
Sad

I have resolved in this way

bit_clear(TRISLED1); // ra4 is output
bit_clear(LED1); // led is on

bit_set(LED1);
bit_set(TRISLED1); // led is off ra4 is input

all ok, it works !!

@lorenzo: sei italiano ?
ericzuki



Joined: 24 Feb 2004
Posts: 3

View user's profile Send private message ICQ Number

Enquiries
PostPosted: Wed Apr 28, 2004 10:33 am     Reply with quote

Can i check with you. Did you put a pull up resistor on RA4 in order to solve the problem or just by adding the following command

bit_clear(TRISLED1); // ra4 is output
bit_clear(LED1); // led is on

bit_set(LED1);
bit_set(TRISLED1); // led is off ra4 is input
Max



Joined: 15 Dec 2003
Posts: 51
Location: Italy

View user's profile Send private message

PostPosted: Wed Apr 28, 2004 2:01 pm     Reply with quote

schematic never changed:
RA4 +-------+R 220ohm +------+ LED +-------+ VDD
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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