Hi all, I'm working on a project at the moment that requires quite a lot of stuff to happen as quickly as possible.
Basically, I am working on a lightweight electric vehicle/controller management system, and as such, the main uC has to handle quite a bit of stuff, such as reading cell voltages from a LiPo battery, measuring current draw, current speed, reading a throttle input and outputting a PWM control signal etc etc. I have all the hardware design done using a 328.
My idea thus far is something like this: Keep timer0 intact for millis() and such, timer1 needs to stay untouched for the PWM to work, leaving me timer2. I have my brake connected to Pin 2 on an interrupt.
I was considering setting up timer2 to overflow at say, 50ms, and run the throttle routine, so that the throttle stays responsive all the time.
However, I also want to be able to measure current ground speed using a reed switch on the back wheel. Pretty much all I have left at this stage is the hardware interrupt on pin 3, however then there is the possibility it may override and thus miss the brake interrupt, which is a no-go. Pulsein is a blocking function and will slow down my loop, so it's not really an option.
So, I'm wondering, is there a way to say, give 1 interrupt priority over another in some way?
Both interrupts would only be required to set a variable or 2, so they would take very little time, but the possibility is still there.
Does anyone have any better ways/ideas I could 1. Timer interrupt the throttle code to run every 50ms or so, 2. Have a brake interrupt that can override everything (Or at least, can trigger straight after the speed interrupt), and of course, count pulses from a reed switch?
Can timer2 be used as a counter as well?
On 2nd thoughts I probably should have gone with a more capable uC, but I should be able to get this to work well enough I hope.