SV: [Icc-avr] Software Delay
Bengt Ragnemalm
benra at imt.liu.se
Tue Jan 8 23:34:40 PST 2008
I would recommend filtering (digitally) the input instead of just a delay.
Just a simple averaging will do.
/Bengt
> -----Ursprungligt meddelande-----
> Från: icc-avr-bounces at imagecraft.com [mailto:icc-avr-
> bounces at imagecraft.com] För Andrew
> Skickat: den 8 januari 2008 22:51
> Till: Discussion list for ICCAVR and ICCtiny Users. You do NOT
> needtosubscribeto icc-announce if you are a member of this.
> Ämne: Re: [Icc-avr] Software Delay
>
> I have fixed my progam using the good old method of flip a pin and use the
> oscilliscope.
>
> i have basically change the main code to have a delay after it sees the
> pin
> go high then the code cheks the pin again if it is high go to sleep
> otherwise ignore.
>
> ANdy
>
>
>
> ----- Original Message -----
> From: "Andrew" <andrew_166 at msn.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: Tuesday, January 08, 2008 6:03 PM
> Subject: Re: [Icc-avr] Software Delay
>
>
> > Hi,
> >
> > I am using edge triggering on INT1. basically i have a switch IC that
> send
> > INT1 high when the AVR is running on a battery and low when it is
> running
> > on main power. so i my main while(1) loop i poll PORTD Bit 1. if it is
> > high i set the first enble the INT1 interrupts and set them to falling
> > edge and then go to sleep. When the systems wakes i disable the pin
> > interrupts and wake the avr.
> >
> > void sleep(void)
> > {
> > DF_Deep_Power_Down(); // Put DataFlash one in deep sleep
> > NOP(); // Small Delay
> > DF_Deep_Power_Down_2 (); // Put DataFlash two in deep sleep
> > NOP(); // Small Delay
> >
> > DDRB = 0x00; // Tri-State PORTB
> > DDRC = 0x00; // Tri-State PORTC
> > DDRD = 0x00; // Tri-State PORTD
> > PORTB = 0x00; // Make Sure the port is not pulled-up
> > PORTC = 0x00; // Make Sure the port is not pulled-up
> > PORTD = 0x00; // Make Sure the port is not pulled-up
> >
> > SPCR = 0x00; // Power Down the SPI
> > TCCR1B = 0x00; // Stop timer
> > TIMSK1 = 0x00; // Disable Timer Intterupts
> >
> > REGCR = 0x01; // Disable the USB Regulator (Make Sure as is not used for
> > this project)
> >
> > PRR1 = 0x81; // Turn Off the USB and USART using the power reduction
> > register
> > USBCON = 0x00; // Disable USB By clearing USBE: USB macro Enable Bit
> > PLLCSR = 0x01; // Turn The USB Clock OFF (PPL)
> >
> > EIMSK = 0x00; // Clear Interrupts
> > EICRA = 0x08; // Change INT1 Pin Interrupt to Falling Edge (INT1)
> > EIMSK |= 0x02; // Enable Interrupts on INT1
> >
> > SMCR = 0; // Clear SMCR Register
> > SMCR = 0x05; // Configure Sleep Register for Deep Sleep
> > asm("sleep"); // Put Processor into Deep Sleep
> > }
> >
> >
> >
> > void wake (void)
> > {
> > PLLCSR |= 0x02; // Enable the USB Clock (PPL)
> > PRR1 &= ~ 0x81; // Restart the USB from Power Reduction Mode
> > USBCON = 0x80; // Rest and Re-Start the USB
> >
> > init_devices(); // Re-Start all devices
> > EIMSK = 0x00; // Disable Interrupts
> > EICRA = 0x00; // Clear Interrupt Condition
> >
> > DF_Deep_Power_Resume(); // Wake Data Flash 1 from deep sleep
> > NOP();
> > DF_Deep_Power_Resume_2(); // Wake Data Flash 1 from deep sleep
> >
> > NOP();
> > NOP();
> >
> > if ((!BAT_CONNECTED) && (!USB_CONNECTED))
> > {
> > Active_count++;
> > }
> > }
> >
> >
> > as you can see i have a counter that tells me how many times the battery
> > (aka the avr has been asleep) but for some reason the counter sometimes
> > increases more than one count say from 4 to 7. if i follow the logic in
> my
> > main code i cannot see how this is happening unless the polled INT1 is
> > still bouncing after the AVR has woken up, which means it will go back
> to
> > sleep. maybe i need a delay at the end of my wake command? Here is the
> > main code can anybody here see anything wrong? (NOTE this is driving me
> > mad)
> >
> > //----------------------------------------------------------------------
> -------
> > // Main Program Loop
> > //----------------------------------------------------------------------
> -------
> > void main(void)
> > {
> > USB_Buffer_Clear(); // Make sure the USB buffer is clear
> > bFlags = 0x00; // Clear Flasgs
> > Active_count = 0x00; // Clear Active Count
> >
> > init_devices(); // Initilise all the devices
> >
> > usb_scheduler_init(); // Start USB Scheduler
> >
> > while (1)
> > {
> > if(BAT_CONNECTED && (!USB_CONNECTED)) // If the Battery Connected Pin is
> > high
> > {
> > sleep(); // Call the Sleep function
> > NOP(); // Small Delay
> > NOP(); // Small Delay
> > wake(); // Wake from Sleep and restart USB and SPI
> > }
> >
> > if(!TestBit(bFlags,TEST_MODE))
> > usb_scheduler_tasks();
> > }
> > }
> >
> >
> >
> > Best Regards,
> >
> >
> >
> > Andy
> >
> >
> >
> > ----- Original Message -----
> > From: "John Baraclough" <j_baraclough at zetnet.co.uk>
> > To: "Discussion list for ICCAVR and ICCtiny Users. You do NOT need
> > tosubscribe to icc-announce if you are a member of this."
> > <icc-avr at imagecraft.com>
> > Sent: Tuesday, January 08, 2008 5:25 PM
> > Subject: Re: [Icc-avr] Software Delay
> >
> >
> >> Debouncing inside an interrupt is a very bad idea. You should either
> use
> >> edge triggering on INT1 or a software debounce that isn't in an ISR.
> >> There's a lot of good stuff about debouncing in Jack Ganssle's article
> >> which you can find here <http://www.ganssle.com/debouncing.pdf>.
> >>
> >> All the best for now,
> >> John
> >> <www.ganssle.com/debouncing.pdf>
> >>
> >> Andrew wrote:
> >>> 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 : -
> >>> <code snipped>
> >>>
> >>>
> >>> 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
> >>>
> >>
> >> _______________________________________________
> >> Icc-avr mailing list
> >> Icc-avr at imagecraft.com
> >> http://dragonsgate.net/mailman/listinfo/icc-avr
> >>
> >
> > _______________________________________________
> > Icc-avr mailing list
> > Icc-avr at imagecraft.com
> > http://dragonsgate.net/mailman/listinfo/icc-avr
> >
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
More information about the Icc-avr
mailing list