First off, I think i'm getting to the end of the Inchworm woods!! haha Its working GREAT at the moment!
I have learned enough assembly to modify a program I found on the net to blink LEDs. I have made several patterns with 8 leds, but the program ends up being quite long. I need to see if there are simpler ways of doing things.
Question 1. How do you tell how big your program is? I assume I will get an error if I try to fit more then the PIC can hold?
2. After I program a PIC with the inchworm, will the PGD and PGC pins (RB6 and 7 on a 16F628) become avalible for general use when the PIC is in the project it will be controlling?
3. I want to select from 4-6 led patterns with a rotary switch. Is this possible/advisable with a single PIC? I assume I could use 4-6 seperate PICs, one for each pattern, but I am guessing thats not needed. Does anyone have a schematic or link to a similar project so I can get an idea on how this is done?
First off, I think i'm getting to the end of the Inchworm woods!! haha Its working GREAT at the moment!
I have learned enough assembly to modify a program I found on the net to blink LEDs. I have made several patterns with 8 leds, but the program ends up being quite long. I need to see if there are simpler ways of doing things.
Question 1. How do you tell how big your program is? I assume I will get an error if I try to fit more then the PIC can hold?
It should be listed somewhere on you assembly listing.
The easy way in MPLAB is to VIEW>Memory Usage Gauge.
Andy1845c said:
2. After I program a PIC with the inchworm, will the PGD and PGC pins (RB6 and 7 on a 16F628) become avalible for general use when the PIC is in the project it will be controlling?
Yes if you program it. I would unplug the programming cable prior to running if you are using ICSP.
No if you are using the debugger.
Andy1845c said:
3. I want to select from 4-6 led patterns with a rotary switch. Is this possible/advisable with a single PIC? I assume I could use 4-6 seperate PICs, one for each pattern, but I am guessing thats not needed. Does anyone have a schematic or link to a similar project so I can get an idea on how this is done?
A single PIC is OK.
Use a LED matrix. You can build or buy one.
Source a column, sink the rows you want to turn on sort of thing.
Store patterns in memory.
You could use a push button if you do not mind cycling through the patterns. A rotary switch would work but takes more port pins.
I am sure you can find a tutorial on the web. Start with Nigels site.
1. Assuming during desgin time and using MPLAB, go to View->Program Memory and look at the left column "Line". Line is the decimal number for the number of bytes the program is using. The code ends when you see a series of 3fff or ADDLW 0xff Once you get into things, you will need to use the Program Memory window frequently. You can also look for "...Programming Program Memory (0x0 - 0x437)" in the MPLAB ICD 2 Output tab. In this case my program ended at 437 hex or 1079 dec.
3. Do not use extra PICs for extra patterns. Rotarys are okay.... yet are so limited and consume to many lines of which you cannot spare for your small pin chip and large count of leds. Try rotary pulse generator. Optical or not, just something that sends a pulse. This way only one 1 i/o line is used.
2. I do not use inchworm so what I do for testing projects I use breadboards and have 5 colums dedicated for programming. When not programming I just pull off the 5-pin headers if the programming lines will interfer with normal usage, else leave the programmer connected and it powers the board as well. For dedicated PC boards I use a double-pole-double-through push button switch. It physically removes the programming pins from the PIC and connects the loads the the PIC with a single tap. See pic-dongle sample below. The programming cable plugs in to the left side. Same is done on my test breadboards
I have done an application using the 8-pin dip 12C509 chip, driving 5 sets of series wired LED's for a small x-mas tree application. (The one Pin is Input only). With 5 pins, Bin 11111 = Dec 31 (i.e. 32 different patterns available)
I used Nigel's tutorial for storing the patterns, and then made them cycle trough 10 times at different delay speeds between each output series.
The result is a x-mas tree that seems to have random lights flashing, and it keeps my 2 year old boy quite happy
But for the rotary switch you mentioned its wasting another more PIC pins. If you are using PIC16f628A the maximum LEDs will be 8.bcuz other remaining pins used to the rotary switch (8+8).
It’s easy if you use a single switch to change your patterns. Using the external interrupt pin is very usefull in this case to place your switch.
Here's one of many PIC Tips & Tricks guides (can be hard to find on Microchips site). This includes running many LEDs from only a few I/O pins and more.
A push button would be okay, but the rotary switch would be ideal. I want a master power switch and then a roatary to select the pattern.
With a rotary, lets just say a 6 position, would I use 6 pins as input, and then when the PIC gets power to it, have the program check to see what pin has voltage and from that decide where in the program to start running? Would that be a crude description of what I need to learn to do?
3v0 - I found the Memory Usage Gauge in MPLAB, but it showed 0 on both sides I'll look into it more tonight.
With a rotary, lets just say a 6 position, would I use 6 pins as input, and then when the PIC gets power to it, have the program check to see what pin has voltage and from that decide where in the program to start running? Would that be a crude description of what I need to learn to do?
The switches are usually connected between the PIC inputs and ground and you have to check which pin is low (=selected). This can be done once, but you may want the pattern to be changed without powering the PIC off. For example, when you change the pattern, the program can call a different subroutine and the LEDs are lit accordingly.
Here's one of many PIC Tips & Tricks guides (can be hard to find on Microchips site). This includes running many LEDs from only a few I/O pins and more.
I also want to Learn about Capture, Compare Modules in PIC, Infact i want to know that what they are and their application examples.... Any guide related to it???
The switches are usually connected between the PIC inputs and ground and you have to check which pin is low (=selected). This can be done once, but you may want the pattern to be changed without powering the PIC off. For example, when you change the pattern, the program can call a different subroutine and the LEDs are lit accordingly.
Use a single pushbutton, and write a value to the flash ram (EEPROM) on a 16F628A... The data is easily read / changed while the chip is running, and power cycled.. You've now saved 7 lines to do "other stuff"....
I'm currently using a 16F628A in a rocketry application with 5 input switches, 2 x 16 line parallel LCD, and 3 mosfet driver lines.
Proton makes the coding sooo simple. I've tried to learn assembler, but I am way too thick to take it all in. With Proton, I was able to write fully working code (that is easily tweakable) for a commercial application within a day of opening and installing the product. Sorry if that sounds like an ad for a product, but for newbies to coding, it's definitely the way to get used to the architecture of PIC ucontrollers. Try it (free download of the lite version), you might even like it..
Use a single pushbutton, and write a value to the flash ram (EEPROM) on a 16F628A... The data is easily read / changed while the chip is running, and power cycled.. You've now saved 7 lines to do "other stuff"....
He probably doesn't need to save I/O lines for his application: he needs 8 output pins on PORTB, for example, and he can configure 6 pins of PORTA as inputs. If he uses the internal oscillator, other two pins are available for general I/O.
The task should be trivial with a high-level language. Personally I use both C and assembly.
I have learned enough assembly to modify a program I found on the net to blink LEDs. I have made several patterns with 8 leds, but the program ends up being quite long. I need to see if there are simpler ways of doing things.
As you gain experience I'm sure you'll find there are many many ways to write smaller and more efficient code.
Some useful methods you'll come across include the use of tables, indirect addressing, and the use of interrupts and an ISR (interrupt service routine) to automatically perform certain functions as simple background tasks.
For example, you might implement 1.0-msec Timer 2 interrupts and an ISR that counts 1.0-msec "ticks" before performing certain simple tasks. You might break down your LED "patterns" into several tables, each containing "time" byte and "pattern" byte entries (or elements). Your ISR would simply update the LED port with the current "pattern" for "time" number of 1.0 msec interrupt cycles before moving on to the next table "pattern" and "time" entry. Your MAIN program would simply wait for a change in the rotary switch and set another variable that would tell the ISR which LED pattern table to use.
I also want to Learn about Capture, Compare Modules in PIC, Infact i want to know that what they are and their application examples.... Any guide related to it???
3. I want to select from 4-6 led patterns with a rotary switch. Is this possible/advisable with a single PIC? I assume I could use 4-6 seperate PICs, one for each pattern, but I am guessing thats not needed. Does anyone have a schematic or link to a similar project so I can get an idea on how this is done?