Wednesday, August 15, 2007

PIC Analog and Interrupts

Well first, I've figured out how to get analog input finally. There are special calls in MPLab C18 that set up most of it for you. I still have to play around some since it turns out sensitivity can be changed. Anyway, the code can be found here. All it does is change the speed of one of leds depending on the POT's value, and also displays bits [3,11] of the integer representing the value. The two tasks are made independant by having a small delay and just counting foo cycles to pretend their are bigger delays. IE the delay is only 25 but if I want the light to slow down flashing to say 50 I have it wait 2 cycles before toggling, meanwhile the value is still being updated.


My practice of basic interrupts took quite a while. The code is here. Basically it counts down, from input garnered from the dip switches and then when the button is pressed it toggles between being paused and not. Below is a video of it running, note that there is a slight delay since I wait for the button to come up, and it starts of with 2 LEDs lit because of the DIP switch settings:

No comments: