Subject : Re: Problems with port lines - Atmel parts From : "Alistair George" > The problem that I've observed is, that when I've called above procedure > using loop, then it worked 5 - 6 times and then stopped. I've found, that it > is so, becouse P1.0 pin is still in low state and there is no C1 charging, > so the comparator output would be never set to 1. The instruction SETB P1.0 > should be executed becouse the LED was turned off with SETB P1.7. > > Has anyone expirienced similar problems as I? > Maybe there is my mistake in functionality of above hardware/software? Q. Is the car circuit the _only one that you have noticed this problem with setb and clr?? If A. is negative, then its a worry, because we use Atmel parts a lot! I suggest you might be trying to measure a voltage which is higher than the max that the comparitor can compare to eg >(5v-20mv). If your Atmel supply voltage is correct, it should be <6v6, and recommended, be 5v for production spreads. Have you checked the voltage on the comparitor input pin from the car voltage under test, and ensured it is less than 7v. If not, indeterminate events might occur. Regards, Alistair George. Subject : Re: xa problem From : Benjamin Whitehead The way that I have scanned a key-matrix is to use drive-lines that are active low, and sense lines (on the other side of the switch) that are pulled up to Vcc (with a large R in relation to the switch resistance). A key down is indicated with a sense line low, and you know which key in the matrix it is because you drive one drive line at a time. Also take care to 'debounce' the switch. Usually a switch will ring for a few milliseconds before actually closing, depending on the type of switch. Upon sensing a key down, stuff it in memory and check back a little later to be sure that it is really down. You may also need to consider 'phantom' keys. Subject : Re: Philips Microcontroller Forum Digest - Issue : 970529 at 10:57 From : derek@lancom.com > > Message 2 : > Subject : Problems with port's lines > From : pklawitter@lucent.com > > > Nothing specific but from grim experience I suggest that before you try any microcontroller based electronics in an automobile you look at a couple of applications notes. An old one from Intel - AP-125 "Designing Microcontroller Systems for Electrically Noisy Environments". A couple from SGS-Thomson: AN553/1292 "Protection Standards Applicable to Automobiles", AN554/0303 "Choice of Protection in Automotive Applications (Classival Topology)". Subject : Re: roblems with port's lines From : Philippe >1. Clear the P1.0 to discharge C1. >2. Reset ACC - time counter. >3. Set P1.0 - starts charging of C1. >4. Check if P3.6 (comparator output) is equal 1 (voltage on (+) input is > higher than on reference (-) input). > If so, than go to step 7. If not - step 5. >5. Increment ACC. >6. Go to step 4. >7. Calculate the time from ACC into voltage and display it. ....... >so the comparator output would be never set to 1. The instruction SETB P1.0 >should be executed becouse the LED was turned off with SETB P1.7. According to the data sheet: " Some instructions that read a port latch read the latch and others read the pin. Read-modify-write instructions read the latch rathe than the pin, and these instructions read a value, possibly change it and then rewrite it to the latch." ..... "" MOV PX.Y, C CLR PX.Y SETB PX.Y The last three instructions in this list are read-modify-write instructions, because they read all 8 bits of the port byte, modify the addressed bit, then write the new byte back to the latch. Read-modify-write instructions are directed to the latch rather than the pin in order to avoid misinterpreting the voltage level at pin. For example z port might be used to drive the base of a transistor. When writting to the bit, the transistor is turned on. If the CPU reads the same port bit at the pin rather than the latch, it will read the base voltage of the transistor and interpret is a 0. Reading the latch rather than the pin will return the correct value of 1. "" Then, this explain why reading a bit, reset another on the same port. Here the instructions which read the latch rather than the pin: inst.: example: ANL ANL P1,A ORL ORL P1,A XRL XRL P1,A JBC JBC P1.1, label CPL CPL P3.0 INC INC P2 DEC DEC P1 DJNZ DJNZ P3,label MOV PX.Y, C CLR PX.Y SETB PX.Y But your program seems to take care of this matter and it seems to be another reason at your problem as you say sometimes SETB command is not performed at all. Reading again data sheet, it seems to be another reason. I recommand you to read carefully ATMEL data book page 2-43 and 44 and look at figure 5 on port structure. They explain port has 3 pull-up (which are fet) and say: ..... " The pFET1 transistor in figure 5 is turned on for 2 oscillator periods after a 0-to-1 transition in the port latch. While pFET1 is on, its turns on pFET3 ( a weak pull-up) through the inverter. This inverter and pFET3 form a latch that holds the 1. " ...... "If the pin emits a 1, a negative glitch on the pin from some external source can turn off pFET3, causing the pin to go into a float state." When you look at schematic, you will see pFET3 gate is commanded by a retro-action from the pin: ___ VCC gate____| pFET3 | |____________________ PORT PIN ____ | | | /| | | / | | +-------O |---------------------------+ \ | \| Well, if you want to see PORT pin functioning alone, I recomand to put a pull-up resistor (1K for example) to VCC, this will avoid problem with pFET3. See also page 3-19 on port 1 structure. I see a solution at your problem, but it demand some experimentation and additional components, note I don't try this solution but it is a way to explore: Get a FET, for example a J310, then use it to discharge the CAP instead of using CLR P1.0. This solution need another port pin which can be in your case P1.7. R=100 ___ |--------___----- P1.7 -------| FET to cap |---------------- Then you must modify your program in order to set P1.0 always as input with a SET P1.0 command. Note also, 8051 serie will prefer to sink curent from GROUND to VCC instead of VCC to the GROUND: IOL = 20mA, IOH =-80 micro-A. Another extreme solution is to use a PIC or a 68HC705 which does not have such pull-up problem as they use "real I/O" port. Hope this help you, regards, Philippe. Subject : Re: Philips Microcontroller Forum Digest - Issue : 970529 at 10:57 From : Ivan Zilic Hello ! > Subject : Problems with port's lines > From : pklawitter@lucent.com > I'm using AT89C2051 chips for about a year. Discusion about Atmel's microcontrollers is probably not very welcomed in this forum... ;-) > I've noticed, that sometimes the SETB command doesn't work for > port lines. All pins have internal pull-ups _except_ P1.0 and P1.1 - because of the on-chip analog comparator. > Here is the problem scenario: when for particular > port line (i.e. P1.0) the commands CLR P1.0 and SETB P1.0 are > used with not much time between them, then in 80% command SETB > is working correctly, but in 20% it looks like there was no SETB > command performed at all! Microcontroller is not able to 'push' P1.0 and P1.1 outputs over logic '1' min. limit level without external pull-up resistors. You might see, that when you set P1.0 output, voltage remains somewhere between logic '0' and '1' levels, so sometimes this voltage is 'interpreted' in circuit as logic '1' and sometimes as '0'. If you add also 'real world' to that kind of circuits, outputs P1.0 and P1.1 could be changed randomly and without software commands... Subject : Re: Philips Microcontroller Forum Digest - Issue : 970529 at 10:57 From : WAGNERL@ix.netcom.com Fred Covan, You need to be sure that you are initializing the input port with "1" (with an output instruction). The Input pin is in reality also an output pin all the time until you command the read instruction. Another recommendation is just include one pullup resistor at each one of the four input lines, by this way you can ensure a good response (reading) from the keyboard (10k is enough). I use the same fashion of keyboard reading, but you don't need to keep polling each one of the output (3) lines and then read the 4 lines to see if any key is pressed, just activate all the 3 output lines and read the 4 input lines at once, if you have a reading that indicates one key pressed, then you can poll each one of the 3 output lines and read the 4 lines to identify the pressed key. It saves time. I am sure that you are "deboucing" the readings, it means that after you detect any key pressed, keep reading it as fast is possible for at least 50 milliseconds for a stable contact (if some key no-contact happens during this 50 milliseconds, just reset the counter and start all over again), so you can consider it a debounced key contact. You need to do the same at the time of "contact open" to be sure the key is really not pressed anymore. Wagner Subject : Re: Philips Microcontroller Forum Digest - Issue : 970529 at 10:57 From : flyn@lselec.guild.org (Francis Lyn) +++++++++++++++++++ Re: Piotr Klawitter and 89C2051 Port line Problems Hi Piotr, I presume your application is for measuring 12 Vdc from the automobile system. If so, be very careful that any inputs to the microcontroller are properly filtered to remove high voltage spikes of BOTH polarity. The 12 Vdc power supply in automobiles are electrically very noisy and can cause untold problems to hardware/software; use a zener diode to clamp positive voltage, diode to clamp reverse voltage on input. If you are testing with a clean 12 Vdc supply, the problem is probably with the code. Re: Fred Cowan and XA Keypad scanning. Hi Fred, Your output scan lines should be normally high and pulled low, in sequence, when scanned. Your scan return lines should be tied high with pull-up resistors (say 4k7 to 10k typical). Reason is that XA input lines must be written with 1 (reset state), so they can be pulled low by an input signal (active low). Pressing a key to short a return scan line to an active low scan output will return a low, else return line will read as 1 if key is not pressed. Subject : re : 8031/8255 keyboard scanning From : dogaroiud@pcnet.pcnet.ro (Dorin Dogaroiu) > > >All, > >I know that this is old, it's been done, and it's baby steps. BUT, having >messed around with this thing for a week now, I have to ask for help. I >have a simple 8031 system, standard stuff: 8031, MAX232, E(E)PROM, RAM, and >an 8255. My problem is this: I want to scan a 4x4 keypad on port C of the >8255, and I can't sem to read the darn thing. I can write to it all day. >When I run the sample code I found out on the web, it LOOKS like it should >work, but doesn't. Can we see famous code > The code sets port c LOW nibble as ouputs, and pulses >them, while port c HIGH nibble is set for input, and they are scanned each >time an output is pulsed. The results should be that a key pressed will tie >two pins together, and the code know which one. But it doesn't. I have >since backed off that code, and want simply to read the three 8255 ports, >and display the output on the serial port. For instance, pulling all 8 pins >high on a given port should output h'FF on the serial port. I MUST be doing >something wrong, but for the life of me I can't seem to nail this down. >Anyone care to spoon-feed this to me so I don't choke on it? > Some sugestions : 1 - Did you put pull-up or pull-down resistors on input pins ? ( pull-up resistors if inputs are idle in "1" state or pull-down resistors if the inputs are idle in "0" state ). The 8255 is a MOS device and the status of an unconnected input is unknown, different from TTL devices, where generally the unconnected inputs goes in the "1" state. 2 - did you put serial diodes from outputs to prevent misreading of multiple keys pressed ? 3 - a tipical schematic for scanning 4x4 key looks like this : V V V V | | | | | | | | | | | | R | | R| | R| | R| | | | | | | | | | |-I1 |-I2 |-I3 |-I4 | | | | D | | | | O1 -------|<|-----------|------|-------|-------| | | | | D | | | | O2 --------|<|-----------|------|-------|-------| | | | | D | | | | O3 -------|<|-----------|------|-------|-------| | | | | D | | | | O4 --------|<|-----------|------|-------|-------| | | | | At each wire crossing there is a key. This schematic works for scanning with a "0" output ( from the 4 outputs, one is 0 and the others are 1 ) Diodes are of any type (1n4148...), resistors are 5..100k, doesn't matter. If the program works with scanning with a "1" output, reverse the diodes and connect the resistors to the ground . Subject : Re: 8031/8255 keyboard scanning From : "Cumulus Logic Ltd." Hi Buddy If you want to use port C of 8255 for scanning the keyboard, be sure to have pull-up resistors on input lines of the port (4.7k - 5.6k for example). If you need, I can send some code written for this task, that is tested, works fine and has some facilities like: software debounce, identify if one key is stucked, identify if more keys are hit.