Hardware:
Arduino mini with 328P
soldered on cap to reset for usb-ttl adapter reset
cheap chinese usb-ttladapter
The code:
Stepper driver that uses Timer1 and Timer2 in CTC mode to drive the pins directly, IE no interrupts are used. I will post the actual code when I get backto my desk. The OCR values are based on a value sent over serial and recievied, this I know is going as expected and the variable I use to the set hte OCR is exactly the number I expect in all test cases.
The bug:
When I set OCR1A and watch it's output on my scope it looks fine, exactly as expected.When I set everything the same and invoke OCR2A, suddenly when the OC2A pin is expected to go high, first the RX andTX lines briefly (5us) go low then high again, and in sync with thier transition the OC2A pin goes high. The frequency of the pulse on OC2A does not match the expected frequency given the prescalar settings and the OCR2A value, although it occasionally appears to be exactly halffreq.
Until I post code, is there any conceptual reason Timer2 should be differently behaved? all settings are mirrrored, and the differences in pwm mode and prescaler settings are accounted for. And what on earth could cause the serail lines to twitch like that? The thing that seems wierdest to me is that the computer can still easily communicate with the device even when this is happening, from the serial monitor, and there is no gibberish on the screen.
In revisiting my issue, my diagnosis was wrong. It is not that timer2 does not work, but rather the second timer I start casues the madness. If I send a serial command telling it to start timer1 at a given speed, it happily sets it off in CTC mode. Then when I send a command for Timer2 to start up,all the lines start toggling at a wierd and varying frequency. if i shut off one of the timers, things start working fine again.
they both work independently, but together casue trouble. all 4 associated control registers are set correctly, what am I missing here?
the fact serial com still works despite me seeing pulses on the RX and TX lines (pulses are identical fyi) Iam going to describe my benchtop setup as well to you guys incase it's a stupid hardware setup boneheaded move:
Arduino soldered to a board with no other components, just breaks out pins to some pololu stepper drivers. there is a 12v>5v regulator on the board but it is not being powered right now. the stepper drivers are removed
there are 1 inch flying leads soldered to the arduino which are on a 6pin header, with a capacitor soldered across the reset line. this header goes into the header on the end of my ttl/usb adapter
I have 4 channels and gnd on my xmega portable scope hooked to RX and TX right at the header plug, and two jumpers stuck into the socket where the stepper driver would go to show me the output pulses.
well right before I gave up and went to bed I noticed some weirdness on the ground I was using for the scope. here's to hoping I have a bad solder joint somewhere!
So in my attempt to solder up a nice clean ground on my duino, I failed to connect the power ground for the motors and the logic ground for everything else. the impressive thing is this system was working for months, not sure if a bridge somewhere tiedthe gnds together, or it just backfed and worked or what.
when the problem seems impossible, you have the facts wrong. Everything is beautiful now.