Timeline for Timer2 does not work as it should
Current License: CC BY-SA 3.0
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| S Mar 20, 2014 at 19:25 | history | suggested | jfpoilpret | CC BY-SA 3.0 |
Injected information relevant to the answer, from the current comments.
|
| Mar 20, 2014 at 19:24 | review | Suggested edits | |||
| S Mar 20, 2014 at 19:25 | |||||
| Mar 20, 2014 at 16:56 | comment | added | jfpoilpret | @microtherion maybe but that must reduce the possibilities to share my code with other people as they'll have to do the same cloning work on their installs. I think I'm gonna find a simpler solution to workaround the issue. I already have an idea, I'll post about it later today. | |
| Mar 20, 2014 at 16:53 | comment | added | microtherion | @jfpoilpret, if you truly care about bypassing this code block, it’s very easy to clone a “new” Arduino core from the standard one. | |
| Mar 20, 2014 at 12:14 | vote | accept | jfpoilpret | ||
| Mar 20, 2014 at 12:14 | comment | added | jfpoilpret |
I have just checked wiring.c content and I have to say the init() function content seems to exceed its responsibilities somehow. Obviously there's no usable #if in the function to bypass this code block. Hence I'll have to find another solution to solve my problem. However I consider you have fully answered my question and therefore accept your answer. Maybe I'll edit the content to mention the fact we cannot really bypass this code block.
|
|
| Mar 20, 2014 at 10:54 | comment | added | alexan_e |
@jfpoilpret Normally it would be very easy to use a conditional define (like #ifndef _LEAVE_TIMER2_ALONE_ ... #endif) in wire.c to exclude the timer2 part, but a #define from inside the sketch will not reach it. This can only work if you add the define in arduino.h or wiring_private.h but that is not convenient at all, because if you forget to remove it in an new sketch it will mess things up. Setting the timer inside setup is your best bet I think.
|
|
| Mar 20, 2014 at 10:28 | comment | added | alexan_e | @jfpoilpret The wire.c gets called from init() and if timer2 registers are defined it applies the values shown above, why , I have no idea (one of the reasons I code in native C using AVRstudio). | |
| Mar 20, 2014 at 10:18 | comment | added | microtherion |
Timer2 is used when its associated PWM pins are used with an analogWrite, so the Arduino setup code sets all prescalers to well defined values in case the timers might get used later. I would not try to fight that code; instead, I would just make sure that my setup code runs later, e.g. by moving it to a separate setup() method in your timer class and calling that from the global setup() routine.
|
|
| Mar 20, 2014 at 9:50 | comment | added | jfpoilpret | Do you think there is a way to "disable" this code from wiring.h? | |
| Mar 20, 2014 at 9:49 | comment | added | jfpoilpret | Great! Do you have an idea why wiring.h does that? I mean, normally Arduino default libraries don't use Timer2 on UNO, so this behavior is strange. | |
| Mar 20, 2014 at 9:33 | history | answered | alexan_e | CC BY-SA 3.0 |