Mega8 out of I/O, maybe not?

Go To Last Post
16 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys/gals,

The current design of my board used the Mega8. After changes, I need to add another LED, 1 button and read 2 jumpers. This means I need 4 more IO pins. The problem is that I am out of IO except for the ADC pins and the ISP pins.

My question is: Does anyone see a problem if I use the ADC to read jumpers (I'll put pullups on them, the jumpers will pull to ground) and SHARE the ISP pins with the LED and button?

Rather than move up to a new device, I thought I could load this baby up while I have pins for AVR functions, but used for my application.

Any problems forseen sharing ISP pins for LED and button IO and using the ADC to read 2 jumpers?

Thanks for any input!

Tom

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Does anyone see a problem if I use the ADC to read jumpers (I'll put pullups on them, the jumpers will pull to ground)

But the ADC pins are only ADC if you set them that way. Otherwise they are just regular I/O pins. If you are using some pins on the port as ADC and others as digital I/O, then having the digital inputs change states while reading the ADC might affect the reading, but for static jumpers then there shouldn't be a problem.

Quote:
and SHARE the ISP pins with the LED and button?

Yes, certainly. Though you might need to be careful how you hook them up so they don't interfere with the ISP functionality. At worst you would need jumpers to configure what the pins are connected to.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Koshchi!

I totally overlooked the fact that the ADC pins are regular IO! Duh. I think the best way appoach this would be to use the ISP pins as the pins to read the jumpers. I'll have pullups on them so the ISP should be fine. The jumpers will never be installed (pulled low) during programming. As long as pullups do not interfere with ISP, I'll be fine. 4.75K pullups should be fine on these ISP pins.

Thanks again!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

4.7 should be fine, or you could use the internal right? I don't see any reason the internal pull-ups wont work... along as you don't put reset low (or you can disable ISP if you don't want it, then you can use reset as any other pin) the ISP pins should work fine. I never touch the reset pin unless im programming with ISP or I have a bootloader installed, then I just turn off ISP from fusebits.

just about every pin on an AVR is general IO and function the same as the next one (pull-up,output,input,...), this includes ISP pins, ADC pins, USART pins, and so on...

another thing you could do if all you needed was more on/off style pins (no input) would be to use a shift register! I use the 8bits from Texas interments and there really nice, you can have 8*(how ever many you want) connected to only 3 AVR pins...

the most I have ever connected at one time was 8*5 (8 controllable pins on the shift register * 5 shift register IC's) so 40 pins, all controlled from (any) 3 AVR pins... thats always a neat idea, just they don't support input... adn there really simple to use, you don't need any setup, you just need to turn pins on and off basically.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I like putting pullups on the board and if I do not need them, I do not stuff them. Beats spinning the PCB for a pullup. I will use internals for this one though since I am only reading jumpers. Thank you guys! This beats upgrading to another chip, making a new PCb symbol, new shapecode package, etc... Every pin on this Mega 8 is now offically used... A 100% utilized chip.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nice :) next buy a ATmega2560 and fill its whole flash with code! then buy a ATmega640 and use all its IO pins! :D

Just out of curiosity, what are you making? I always like to see / learn about new projects... epically sense my brain is dead out of ideas at the moment... i mean the last 3 days I have just been playing with bootloaders!!! I need ideas!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For buttons I have used my LCD data lines as inputs (using the lcd as output only -no reading of data lines) by using a weak pulldown (100k) on the pin and the button feed thru a 10k resistor from Vcc.

Pete

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note that the PDIP version has only 6 ADC channels and TQFP/QFN versions have 8 ADC channels. The last two ADC channels ADC6 and ADC7 are not general purpose IO pins, only ADC functionality there.

But in any case, you can still read the jumpers in ADC mode if they have pull-ups. Determine the presence or absence of a jumber by comparing the ADC result with some predefined level, like half of the VREF.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
But in any case, you can still read the jumpers in ADC mode if they have pull-ups.

But why waste the time reading the ADC when you can just read the port directly?

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

But why waste the time reading the ADC when you can just read the port directly?

hes talking about if your using the TQFP/QFN package, I never have so I wouldnt know, but he says the extra 2 ADC's you get with that package over PDIP cannot be used a gen IO.

Quote:
Note that the PDIP version has only 6 ADC channels and TQFP/QFN versions have 8 ADC channels. The last two ADC channels ADC6 and ADC7 are not general purpose IO pins, only ADC functionality there.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

digitool wrote:
For buttons I have used my LCD data lines as inputs (using the lcd as output only -no reading of data lines) by using a weak pulldown (100k) on the pin and the button feed thru a 10k resistor from Vcc.

Pete

Hmm, most TTL-compatible LCD and VFD modules I've seen & used have already had 10k pull-ups on their data lines. Real resistors or built in to the controller chip.

So I think that method would not work with all the display modules out there.

I suggest experimenting with 100k pull-up to VCC (not necessarily needed if the display or AVR has pull-ups ) and the button would then pull down the pin with 1k to GND.

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jani
I tried your method and it works without interfering with the data line during a write to the LCD(if button is pushed at same time) , which I did with my goofy method but you are right that it makes sense to use the pullup method.
Thanks
Pete

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

digitool wrote:
Jani
I tried your method and it works without interfering with the data line during a write to the LCD(if button is pushed at same time) , which I did with my goofy method but you are right that it makes sense to use the pullup method.
Thanks
Pete

Great that it works!

Heh, I kind of like the idea that other people experiment in practice what I have said should work in theory. Maybe I should have stayed longer in the university and be an electronics professor or something :)

- Jani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Good catch! Yes I am using the TQFP package so I cannot simply read the pins directly (ADC6, ADC7) from what you are saying. So can I enable the ADC, but just those 2 pins? I thought the ADC enable was global. My thinking is that once I enable the ADC, you enable all of the ADC pins. Does that sound right?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

>Distraction< If I needed an output for an extra LED I would try my darndest to hook that up to one the ISP data lines so I could watch the blink'n LED while it's programming! No way I could resist the urge to add another blink'n light. I think with proper current limiting resistor (which you need anyways) it wouldn't cause any problems with ISP.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

TMBartman wrote:
Good catch! Yes I am using the TQFP package so I cannot simply read the pins directly (ADC6, ADC7) from what you are saying. So can I enable the ADC, but just those 2 pins? I thought the ADC enable was global. My thinking is that once I enable the ADC, you enable all of the ADC pins. Does that sound right?

Umm, no? Sorry I am not sure how you think the ADC operates, but apparently this is not very clear.

By enabling the ADC does what it means, only enables the internal ADC converter. It does not mean you enable the pins for ADC or disable any normal operations for the pins.

After you have enabled the ADC converter, you can select with the mux which pin, if any, is connected to the ADC at one given time. This does not affect the pin in any way otherwise, but you are able to read a voltage from the selected pin.

- Jani