[Icc-avr] Software Delay
Paul Mateer
paul.aa9gg at gmail.com
Tue Jan 8 09:31:28 PST 2008
Keybounce "delays" can get you into trouble sometimes. I use this code
placed into an timer-overflow interrupt:
#define KEYPADS PINH
unsigned int dbc_j, dbc_i, dbc_idx, dbc_kpd,State[10]; // key-debounce
stuff
interrupt routine()
{
// begin new keypad debounce routine
State[dbc_idx] = KEYPADS & 0xFF;
++dbc_idx;
dbc_j = 0xff;
for(dbc_i=0; dbc_i < 4; dbc_i++) dbc_j = dbc_j & State[dbc_i];
dbc_kpd = dbc_j;
if(dbc_idx >= 5) dbc_idx = 0;
}
On Jan 8, 2008 10:45 AM, Daub, Stephan <stephan.daub at sap.com> wrote:
> Hi andy,
>
> To determine the length of the loop you simpy add the inner loop maschine
> cycles plus the entry cycles plus for/while time. Once you have calc this
> you multiply this with your systemclock and youre done.
>
> Best, stephan
>
> -----Original Message-----
> From: icc-avr-bounces at imagecraft.com <icc-avr-bounces at imagecraft.com>
> To: Discussion list for ICCAVR and ICCtiny Users. You do NOT
> needtosubscribeto icc-announce if you are a member of this. <
> icc-avr at imagecraft.com>
> Sent: Tue Jan 08 17:18:10 2008
> Subject: [Icc-avr] Software Delay
>
> Hi,
>
> I need a good software time delay that sit's in an interrupt handler.
> Basically i need it to de-bounce a pin (INT1). and i cannot use a timer as
> the timer interrupts are disabled at this point in the code.
>
> I was thinking of using : -
>
> #pragma interrupt_handler int1_isr:iv_INT1
> void int1_isr(void)
> {
>
> delay_2();
>
> }
>
>
>
>
> //-----------------------------------------------------------------------------
> //
> // Function name : Delay_2
> //
> // Returns : None
> //
> // Parameters : None
> //
> // Purpose : De-Bouce delay
> //
>
> //-----------------------------------------------------------------------------
> void delay_2 (void)
> {
>
> for (loop_int = 0; loop_int < 100; loop_int++)
> {
> NOP();
> }
>
> loop_int = 0x00;
>
> }
>
>
>
> Only probem is that i have no clue how long this delay is? ( i am running
> the main clock at 8Mhz)
>
>
>
> Does anydy have a better software delay function.
>
>
>
> Andy
>
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
>
--
Paul Mateer, AA9GG
Elan Engineering Corp.
www.elanengr.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://dragonsgate.net/pipermail/icc-avr/attachments/20080108/aac001a3/attachment-0001.html
More information about the Icc-avr
mailing list