NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » how do we use timer1 input capture? (ICP1) on PB0? help?
January 22, 2011 by huzbum |
I've searched and no one on the forum has illustrated a successful attempt at using ICP1. I know it's function can be emulated with a pin change interrupt, but not as efficiently as actually using ICP1. So here are my questions. 1) Can ICP1 be used with the bootloader? 2) If not, can it be used if programmed without a bootloader? Are there any special settings required? I am hoping the staff will have some input here as I know that more than just I wish to use it. A code example would be most helpful, as I'm convinced I'm just doing something small and specific wrong. it wouldn't need to even do anything useful, just an example of the correct way to setup and access the ICP1 function. Thanks for any help. I have little to no experience with MC's and I can't figure out what I'm doing wrong. |
---|---|
January 23, 2011 by Ralphxyz |
Hi huzbum, I sure wish one of the "experts" here on the forum had answered your question. It appears "we" are left with my findings posted on your other thread. What I found out was that you cannot use ICP1 (PB0) unless you remove the bootloader (foodloader). This really seems stupid to me (but what do I know). I mean the Input Capture Function appears to be a valuable function:
Plus there are other functions one can get from using PB0. Apparently the foodloader.c code would have to be changed (and flow logic rethought). I have very quickly looked at foodloader.c and do not see any reference to PB0 or ICP1 so I haven't the foggiest idea where to start with re-writing the foodloader. If you want to use PB0 you have to flash your program directly to the mcu using a programmer utilizing ISP (Inline Serial Programming) or the like. Well like I said I wish others had chimed in with their wisdom. Ralph |
January 24, 2011 by Rick_S |
Ralph, are you saying to use the ICP1 function, the bootloader gets in the way, or to use PB0 the bootloader gets in the way? If so, I wonder why that is? I can say I haven't messed around much with it but I thought once you were into your own code, you could re-configure any port as needed to use any way. Did you ever get a reason as to why it couldn't be done? Rick |
January 24, 2011 by Ralphxyz |
If the bootloader is on the mcu you cannot use the ICP1 (Input capture). With the bootloader loaded PB0 is at Vcc (high). But at very low amperage a LED will just barely glow. So I do not believe you can use PB0 or the ICP1 function with the bootloader loader. Also with the bootloader loaded a jumper between PB4 and PB0 forces the mcu into Programming mode at startup the same as closing the programing switch. I wanted to use ICP1 (input Capture) for the built in filtering, it seems using the hardware native functions to debounce switch closings would be much more efficient than doing it in code. Besides it saves code space. I have quickly looked at the foodloader.c code but do not see the connection to PB0 for the programming switch. Ralph |
January 24, 2011 by huzbum |
Sounds like the pullup resistor is on... maybe turning it off will do it? (page 74 of the atmega168 datasheet)
|
January 24, 2011 by huzbum |
oops... should be an & instead of |
|
January 24, 2011 by mrobbins (NerdKits Staff) |
Hi all, You are correct that once the bootloader passes control to your own code, PB0 is a normal port that might be used for other purposes. You are also correct that the bootloader leaves PB0 in input mode, with pull-up resistor enabled. The only thing to be concerned with is whether your external timing source might pull the pin low during startup, which would make your bootloader stay in its programming mode. Also, take a look at the datasheet -- the Analog Comparator unit can be used as the source for the Timer1 input capture event. That might be an easier way to go! Mike |
January 24, 2011 by Ralphxyz |
Mike, if I load the program that uses ICP1 (PB0) for counter input. I get the two black bars across LCD lines 1 and 3 with the switch in run mode after the program is loaded. If I load the same program using my programmer without the bootloader the program runs fine (doesn't work but runs fine). This is without any connection on PB0 at startup. Ralph |
January 25, 2011 by hevans (NerdKits Staff) |
Hi Ralph, That is indeed quite strange. Assuming nothing else is connected at startup (and you have not modified the bootloader) the chip should boot into run mode. Then in the program code you should be free to turn off the pull up resistor and use the pin as a normal I/O pin. Humberto |
January 27, 2011 by huzbum |
ok, I have a working solution posted in my tach thread: http://www.nerdkits.com/forum/thread/1258/#post8699 but for the sake of making future searches easier, here is the code:
Works without a hitch. Jumper wire directly from PC4 to PB0 (ICP1) to show 120RPM. Doesn't interfere with boot-loader or programming mode. |
Please log in to post a reply.
Did you know that you can connect digital calipers to a microcontroller? Learn more...
|