SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By o_0
#118863
The code in the attachment is for an accelerator-based mouse, interfacing it to the computer via PS/2 protocol. It compiles error free, (note: it's written for Codevision, I've included the hex file in the zip) however when loaded onto a uC, no movement of the mouse cursor is produced. If someone could please help me figure out what is wrong, I would greatly appreciate it.


I don't think the 3-axis accelerator is the problem (it's a MMA7260Q)
http://www.sparkfun.com/datasheets/Acce ... Q-Rev1.pdf
it's giving varied outputs like it's supposed to. The three outputs of the accelerometer are inputs to ADC0, ADC1, and ADC2 of the Atmega32a http://www.atmel.com/dyn/resources/prod ... oc8155.pdf
The 4 outputs of the uC go through an open-collector interface, then to a PS/2 cable from a old PS/2 mouse, then to the computer. I would like to see the mouse pointer moving in response to accelerometer tilt, however no movement is produced.

The version of the code that I've posted uses Port C as outputs:
Code: Select all
#define CLK_OUT PORTC.1    // "C" in the diagram
#define DATA_OUT PORTC.6   // "D" in the diagram
#define CLK_IN PINC.3      // "B" in the diagram
#define DATA_IN PINC.4      // "A" in the diagram
.
.
.
    DDRC = 0b01000010;       
    PORTC = 0b01000010;


I have tried this with the JTAG interface enabled and disabled. The result is the same either way.

I have also tried it with the same pins except on Port D, and changing DDRC to DDRD, etc.
Also, I have tried:
Code: Select all
#define CLK_OUT PORTD.5    // "C" in the diagram
#define DATA_OUT PORTD.4   // "D" in the diagram
#define CLK_IN PIND.3      // "B" in the diagram
#define DATA_IN PIND.2      // "A" in the diagram 
(changing DDRD and PORTD to 0x30)

Open-collector interface
Image
The chip is brand new, I've checked my connections and tried changing the transistors for new ones. I left the fuses at default (internal oscillator 1 MHz).

Here is a summary of what the outputs say: (important ones in bold)
(I can also measure one of the Port D configurations if anyone wants it, but the code was originally written for Port C outputs)-I can also take pictures or video if anyone wants.

Port B: Pins 1-8 all +5V
Reset, Vcc (Pins 9, 10): +5V
GND, Xtal2, Xtal1 (pin 11, 12, 13): 0V
Port D (pins 14-21) all 0V
Port C (pins 22-29):
22: 0 V
23: 0.93 V (pin C.1, clock out)
24: 4.49 V (pin C.2)
25: 0.08 V (pin C.3, clock in)
26: 0V (pin C.4, data in)
27: 4.49V (pin C.5)
28: 0.94 V (pin C.6, data out)
29: 0

AVCC (pin 30): +5V
GND (pin 31): 0V
AREF (pin 32): +5V
Port A (pins 33-40)
Pins 33-37: 0V
Pin 38 (z): 1.99
Pin 39 (y): 1.66
Pin 40 (x): 1.65
(the last 3 vary from roughly 1.4 to 1.8 V with tilt)

Also, I should mention the outputs of Data out and Clock out. They are both +5V for all configurations except Port C with JTAG disabled, in that case both outputs are 0.18 V but drop to 0.13 after 30 seconds or so. Also, I simulated this code in Proteus and at least different parts were going high and low.
You do not have the required permissions to view the files attached to this post.
By o_0
#119155
I also tried a simplified version of the design, where instead of the transistors, the data pins and clock pins are connected by 330 ohms, but it behaves exactly the same way (or rather, it displays the same lack of behavior).

In addition, I changed the frequency to 8 MHz (don't know what frequency it's supposed to be, however I've been told that the operating frequency can be practically anything), changed the accelerometer sensitivity to 1.5g, even put LEDs on pins B0, B2, B5, and B7 like the schematic has. The schematic has all the LEDs going to Vcc. If I have it that way, none of the LEDs ever light. (Measuring it, it's +5V on both sides.) But if I put the LEDs to ground, all four of them will light even if power is off. Also, they are using four accelerometer outputs and I only have three, so the z-axis is connected to ADC2 and ADC3. Still no movement, and all output lines are +5V no matter how much the board is moved around. For PS/2 this is supposed to be the "idle state." But it's not supposed to stay in idle state all the time, the code is supposed to be transmitting stuff, as the accelerometer outputs vary.

Something of note is that with the transistors, the circuit was drawing 0.15 A, but with the 330 ohm resistors instead, there is practically no current drawn (0 or 0.01)
By o_0
#119156
I'm also trying a different code (it's supposed to do the same thing as the other one), but the schematic is different. I've attached both.

I like this design better, but the other one produces fewer warnings. In both cases, most of the warnings are just variables that were created but never actually used.

In this case it's clearly indicated that a crystal was used, though the value was not specified. I used 12 MHz, just because that's what I have. The only other kind I have is 3.6864 MHz (a UART crystal) which doesn't divide evenly into 12.5 kHz.

But this one behaves exactly the same as all the others, i.e., all uC outputs are +5V and I can't get any other kind of response out of it.

---------
Actually I rebuilt it on another board and now all outputs measure 5.47 V. (where Vcc is 5) Is that even possible?

By the way just in case anyone wants to know what's supposed to happen:
http://www.computer-engineering.org/ps2protocol/
You do not have the required permissions to view the files attached to this post.
By o_0
#119161
I should clarify that I like version 2 code because it uses 3 accelerometers and some pushbuttons, instead of 4 accelerometers (1-axis accelerometers are hardly available anymore, very expensive and probably can't find a breakout board). Another difference in my version 2 setup is I'm not using the buffers that they are using.