Wednesday 23 February 2011

Crystal Oscillator and LED 8-Segment display

Another evening, and after originally thinking about ordering some Sockets and Cables for when I eventually get onto outputting DMX, instead I started rooting through my electronics toolbox and found another Crystal, and another of the sliding potentiometers, (100K resistance it turns out)...

So I took the crystal, added the same capacitors I had previously, and added them to the circuit board.  I had to change the oscillator setting in the program to "HS", re-make, program and run the old circuit and yup, the LED flashes a lot lot faster...


The image above shows the crystal and capacitors added to the circuit.  Since the HS Oscillator setting is a little too fast for what I'm doing at the moment I changed it back to "INTOSC_HS" which is meant to be the internal oscillator for program and HS for USB.  Either way it's back to the internal oscillator for now.

Looking at the slider I had, the connection pins fit in nicely to the bread board, but there are four exra pins which I think are meant to be used to fix the slider on to a PCB board... Since I was thinking of programming in the slider again to show how to read inputs I needed to bend those pins back as shownb below:


However thinking about connecting the slider up, I don't actually have any method of telling where the slider is, except for perhaps changing the flash rate of the led... So since I have an 8-segment LED display in the box of LED's, perhaps I should wire that up and use that to display some numbers or letters based on the slider location.

First I needed to find out how to how to wire the LED segment.  A little investigation shows a common +ve connected to pin 3 or 8, and I found all my 1K resistors, so some quick testing to check it out...


So LED's will be on when a pin is set to output and has a value of 0, a value of 1 being off.  The question is where to connect the pions to on the chip... At first I thought to use PORTC as the pins are all down the bottom of the chip, and there are only 7 pins available, (I'm not going to use the decimal point so 7 not 8).

After connecting the segments up to the chip I found that I couldn't figure out how to set two pins, (apparently they could be configured to be outputs if the USB is turned off in one register, but I still failed to get them to output)... In the end I connected two bits from Port B in instead, and then had more fun failing to get those to work as expected... I think I must be using the wrong assembly command to set bits directly as setting the whole PORTB value worked, but not using bcf and bsf...

I have a feeling that I realised the 'obvious' bit set and clear commands didn't do what I expected them to do when I was last trying to learn assembly.  Something to look at later, I've had enough for this evening.  So here's the board layout I had at the end of my fiddling, while the connections are not ideal, for now they're all fine.


At least it looks fairly neat and tidy... Yes I could have just thrown in any old wires, but I like wires all being the right length.. Maybe a bit OCDish, but at least you can follow the wires easily.  If it was wires all-over the place then it can very easily become very confusing!

Oh one thing I almost forgot to say... Trying to connect the board direct to power seems to fail now for some reason, so I must have messed up something somewhere, but it all still works when the programmer is connected with the RESET cleared... so probably something linked to that and maybe the Oscillator... Something to look at another day!

No comments:

Post a Comment