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:

Friday, August 10, 2007

LED Chaser Redux

Okay, so to put it elegantly this is absolutely butt-fucking pointless. On the other hand it was good practice and I learned a few things. Anywho the source code can be found here, it is suprisingly commented for once.

Basically it has modes, that can be set with switches, that dictate how the lights will move(Sweep back and forth, go one way pause and loop, go one way and immediately loop, flash between colors), and has push buttons to increase or decrease the speed.

Below is a video of it running in the dark, I kept it at high speed so I could fit all the modes in a brief amount of time, so it looks a little psychotic:

Thursday, August 09, 2007

PICKIT 2 Programming

I finally got my hands on a decent PIC programmer, and have finally gotten it working. Surprisingly I had more trouble with the compiling of programs than I did with hooking it up physically. The first is figuring out the header files to use, I've always been using p18cxxx.h(For the pic18F chips) and delays.h(This is just for adding waits) which are both needed for any sort of toy programs. The main problem though was pragmas, which took me a while to figure out. The three that I've always been using since it's been working are:
#pragma config WDT = OFF // No clue, but always needed
#pragma config OSC = HS // Use external oscillator

#pragma config LVP = OFF // Turn off LVP Programming


My toy program is a simple LED chaser that goes back and forth and gets progressively faster until it goes so fast it's just flashing all of the LEDs. The source can be found here.

Here's a picture of the breadboard...really only 5 of the LEDs and the microcontroller are used to run it, as well as the oscillator, the rest is just other tinkering. I just left the pickit2 plugged in since I was reprogramming it alot, except I've always been having to swap the voltage on the pickit2 with the voltage on the breadboard: