From: Jim Brain (brain_at_jbrain.com)
Date: 2007-04-11 02:10:48
Hársfalvi Levente wrote: > -- On the PIC, one instruction cycle is 4 clock cycles. A 4 Mhz PIC is > effectively an 1Mhz MCU (see > http://ww1.microchip.com/downloads/en/DeviceDoc/39582b.pdf, page 159 > ... I wonder why they don't put more emphasizing on this fact ;-))) ). > An Atmel AVR, clocked at 4Mhz is a 4Mhz MCU. Yeah, I skipped this portion, for brevity, and because I didn't want to offend the PIC folks. Some PICs come in 40MHz variants, which means 10MHz effective, though I believe you have to use a Xtal for that. > You can probably take Jim's sources that he has published... I haven't > tried his code, but if he tested it and it could do 3...255 > proportionally / without jitter, then it should be well useable. (BTW, > as I suspect not even the original Commodore paddles would My solution to prevent jitter was to use the internal oscillator function in AVRs (some PICs have this as well, just to be fair). I set the oscillator up for 8MHz (fastest), and then start watching the POT line. When I see a zero-clamping of the POT line, I check the timer and reset it. If the number is != 8*512, then I trim the oscillator using the OSCCAL register to speed up or slow down the oscillator. I use a threshold factor for the trigger (4096+-16 or so) to prevent constant "hunting" for the right speed and to deal with the limited resolution of the OSCCAL. As a result, you see the interface "hunt" for a few periods at the beginning. If the number is way off (the 4066 selects the other paddles, and then switches back, the code ignores and continues. But, I won't guarantee the code is great. It's good enough. Perfection is a luxury not enjoyed much anymore. It's not half bad C at that, but it's by no means innovative. In short, standard disclaimer about my code not being truly "hacker" worthy applies. The only issue I have is if both paddles are exactly at the same position. Since both are running on their own timer, and I use the output compare IRQ, both then fight to be triggered first, and one loses, delaying by 1uS or so (in reality, if you turn one paddle to 27, and then turn the other one from 80 to 25, it'll go 29,28,26,25). Changing the code to run one compare when both values are equal could be done, but the resulting code got heavy and hard to debug, and I decided I didn't need that level of perfection. Begging forgiveness for my ignorance, is it Mr. Levente, or Mr. Hársfalvi? (ie, which is first name, and which is surname?) Are there some general rules someone less cultured like I can use to denote which is which? Jim -- Jim Brain, Brain Innovations (X) firstname.lastname@example.org Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times! Home: http://www.jbrain.com Message was sent through the cbm-hackers mailing list
Archive generated by hypermail pre-2.1.8.