??? 03/24/08 00:40 Read: times |
#152467 - Note Length & Cadence on One Timer Responding to: ???'s previous message |
A.S.Rudra:
It should be reasonably straightforward to use one timer for the note duration and for the cadence measurements. The trick here is to not think it is necessary to directly program this timer to the length of the note. Instead program the timer for a periodic interrupt at a rate that corresponds to the resolution you need for the note timing. For example if you can do all your note lengths in one millisecond steps then program this interrupt to happen once per millisecond. The note duration then simply becomes a counter that you maintain at each occurance of the interrupt. Likewise the tone cadence, (i.e. on/off times and repeat cycle time), is managed by additional counters in the interrupt routine with one millisecond step size. If it turns out that you can live with a resolution of 1/100th of a second instead then set this timer to run every 10 milliseconds. Detection of the ten separate inputs as parallel GPIOs to the MCU can be easily done with minimal code in a 10-msec interrupt (or once each 10 interrupts of a 1-msec interrupt) task. You could download some input scanning code I have done in the past and modify it to suit your application. In my sample I was supporting 8 inputs and so all the variables and function arguments use unsigned char values. You could modify this to use unsigned int (16-bit) values and support parallel detection and debounce for 9 to 16 inputs. The scan routine is called from a repetitive interrupt routine (10 msec recommended) and where you input your 10 inputs simply merge them together into 10 bits of the unsigned int input value for the key scan logic. The other various routines in the module can be called by your mainline code to determine the state or status of any one of the inputs such as current state, queued going ON detection or even the queued going OFF detection. Note that if you do end up modifying my code to support unsigned int 16-bit values you may have to consider disabling interrupts for a few instructions around the references to the global variables in the mainline routines since the 8051 type MCU can only access 8-bits at a time from a 16-bit variable and a half processed variable access could be buggered by the interrupt scan happening right at the time a variable is half referenced. Good luck Michael Karas |