Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A couple PIC questions.

Status
Not open for further replies.

Andy1845c

Active Member
First off, I think i'm getting to the end of the Inchworm woods!! haha Its working GREAT at the moment!:D

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?
 
Andy1845c said:
First off, I think i'm getting to the end of the Inchworm woods!! haha Its working GREAT at the moment!:D

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


**broken link removed**
 

Attachments

  • img-schematic-8led3.gif
    img-schematic-8led3.gif
    20.4 KB · Views: 167
  • pic-dongle.jpg
    pic-dongle.jpg
    48.2 KB · Views: 181
Last edited:
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;)
 
Hi Andy1845c it’s possible with a single PIC.

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.
 
Last edited:
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.
 

Attachments

  • PIC Tips & Tricks Hardware Techniques.pdf
    488.5 KB · Views: 327
Thanks everyone for the replys.

I only need output on 8 pins.
This is what I am trying to build.
https://www.youtube.com/watch?v=LvQFHBqHsew
Only mine will have 8 lights insted of 6.

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:confused: I'll look into it more tonight.
 
Andy1845c said:
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.
 
blueroomelectronics said:
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.
It is realy very informative....
Thanks to u.

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???
 
eng1 said:
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..
 
Shax said:
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 would use a single push button, but the OP said:
Andy1845c said:
A push button would be okay, but the rotary switch would be ideal.
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.
 
Last edited:
Andy1845c said:
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.

Take care. Have fun. Regards, Mike
 
Last edited:
Ayne said:
It is realy very informative....
Thanks to u.

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???
Why yes there is...
 

Attachments

  • PIC Tricks CCP PWM.pdf
    394.9 KB · Views: 328
  • PIC Tips POWER.pdf
    978.4 KB · Views: 702
  • PIC AN594 Using the CCP.pdf
    263.3 KB · Views: 370
  • PIC Tips & Tricks 3v.pdf
    952.8 KB · Views: 481
Last edited:
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?
The trick is to convert from 1 of n to binary.

The attachment is an extract for one of my designs. I've converted 1 of 10 to binary using a 2 gang rotary switch.

It could be done with a one gang switch by:-
  1. using more diodes, or
  2. using a Priority Encoder IC.
In the case of a one gang, 4 position switch (ie. n = 4 ), all you need is 2 diodes and 2 resistors.

But if you use a 4 position, 2 gang switch, all you need is 2 resistors.

EDIT, I mis-read your request. You want 6 LED patterns.

So you can do it with a 2 gang 6 position switch and 3 resistors as per the 0 ~ 5 positions in the attachment,
 

Attachments

  • Rotary switch.gif
    Rotary switch.gif
    4.2 KB · Views: 147
Last edited:
Gayan Soyza said:
donniedj I like your PCB.Are you using the tonner tranfer method or silk screen method.

Photolithograpic method with printed on transparency sheets.
 
You can use a single ADC to select different subroutines with a multiple point potential divider. Read the ADC value to call different subroutines.

:eek:hm:
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top