problema antirimbalzo pulsanti e interruttori

Sezione dedicata al sistema di sviluppo BASCOM-AVR per i micro AVR
At90s, Attiny, Atmega e Xmega

problema antirimbalzo pulsanti e interruttori

Postby adriano » 04 Mar 2013, 16:04

Buongiorno ,

pongo un problema e in parte ( si come cerco di non aspettare “ la pappa pronta” ) mi sono dato in parte la risposta …il comando da usare e il “DEBOUNCE”
il problema del rimbalzo , fenomeno legato al rimbalzo dei contatti di chiusura di un pulsante o interruttore . Ora , si come google traduce ma il senso del testo non è proprio chiaro , mi spiegate gentilmente cosa avviene in questo codice e le cose fondamentali per usare il comando .
Grazie.
Ps: questa settimana vi disturberò solo per questa cosa e cerco di capire da solo il “pwm” , i timer e come calcolare la frequenza ,,,, poi non vi disturbo più per almeno 20 giorni . Se imparo queste due cose , ho materiale per sperimentare almeno un mese.
.... scusate se ho fatto un po’ di confusione nel forum ed ho scritto un po’ qua …un po’ la …vi chiedo scusa . …
Necessito per cortesia spiegazione più sintetica possibile ed il minimo necessario per usare il comando:

When you specify the optional parameter SUB, a GOSUB to label is performed instead of a GOTO.
The DEBOUNCE statement tests the condition of the specified pin and if true there will be a delay for 25 mS and the condition will be checked again. (eliminating bounce of a switch)
When the condition is still true and there was no branch before, it branches to specified the label.
When the condition is not true, or the logic level on the pin is not of the specified level, the code on the next line will be executed.
When DEBOUNCE is executed again, the state of the switch must have gone back in the original position before it can perform another branch.
So if you are waiting for a pin to go low, and the pin goes low, the pin must change to high, before a new low level will result in another branch.
Each DEBOUNCE statement, which uses a different port, uses 1 BIT of the internal memory to hold its state. And as the bits are stored in SRAM, it means that even while you use only 1 pin/bit, a byte is used for storage of the bit.
DEBOUNCE will not wait for the input value to met the specified condition. You need to use BITWAIT if you want to wait until a bit will have a certain value.
So DEBOUNCE will not halt your program while a BITWAIT can halt your program if the bit will never have the specified value. You can combine BITWAIT and DEBOUNCE statements by preceding a DEBOUNCE with a BITWAIT statement.


See also

CONFIG DEBOUNCE , BITWAIT

Example

Code: Select all
'-----------------------------------------------------------------------------------------
'name                     : deboun.bas
'copyright                : (c) 1995-2005, MCS Electronics
'purpose                  : demonstrates DEBOUNCE
'micro                    : Mega48
'suited for demo          : yes
'commercial addon needed  : no

'-----------------------------------------------------------------------------------------
$regfile = "m48def.dat"                                   ' specify the used micro
$crystal = 4000000                                         ' used crystal frequency
$baud = 19200                                               ' use baud rate
$hwstack = 32                                               ' default use 32 for the hardware stack
$swstack = 10                                               ' default use 10 for the SW stack
$framesize = 40                                             ' default use 40 for the frame space

Config Debounce = 30                                       'when the config statement is not used a default of 25mS will be used but we override to use 30 mS

'Debounce Pind.0 , 1 , Pr 'try this for branching when high(1)

Debounce Pind.0 , 0 , Pr , Sub
Debounce Pind.0 , 0 , Pr , Sub
'                                      ^----- label to branch to
'                          ^---------- Branch when P1.0 goes low(0)
'                     ^---------------- Examine P1.0

'When Pind.0 goes low jump to subroutine Pr
'Pind.0 must go high again before it jumps again
'to the label Pr when Pind.0 is low

Debounce Pind.0 , 1 , Pr                                 'no branch
Debounce Pind.0 , 1 , Pr                                 'will result in a return without gosub
End

Pr:
     Print "PIND.0 was/is low"
Return
Mai mi fu dato di vedere un animale in cordoglio di sé. Un uccelletto cadrà morto di gelo giù dal ramo senza aver provato mai pena per sé stesso.
User avatar
adriano
 
Posts: 108
Joined: 17 Feb 2013, 11:07

Re: problema antirimbalzo pulsanti e interruttori

Postby deluca » 04 Mar 2013, 19:55

salve adriano,

PS. Intanto ti mostro come strutturare al meglio un post nel caso in cui è posto in allegato un esempio demo, come quello da te evidenziato.

usa "QUOTE" per frasi prese dall' HELP e "CODE" se si tratta di codice.

Appena possibile.... segue aiuto.
ciao
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)

Re: problema antirimbalzo pulsanti e interruttori

Postby deluca » 04 Mar 2013, 20:49

ecco la spiegazione......
Se tu specifichi il parametro opzionale "SUB" alla fine del comando DEBOUNCE verrà eseguito un GOSUB alla label specificata invece del salto GOTO senza return.
Il comando debounce testa lo stato di un determinato pin. se è "true" aspetterà altri 25 msec (valore di default configurabile) e la condizione verrà ricontrollata di nuovo eliminando in questo modo l'effetto di debouncing.
Per riattivare la funzione, il pin del pulsante deve ritornare nello stato "false".

spero sia stato chiaro.
ciao
Ciao
Il mio sito: http://www.delucagiovanni.com ......e la chat: chat/
User avatar
deluca
Site Admin
 
Posts: 1104
Joined: 19 Jun 2011, 10:44
Location: 95123 - Catania (Italy)

Re: problema antirimbalzo pulsanti e interruttori

Postby adriano » 09 Mar 2013, 15:36

Grazie deluca , ora che ho il pc funzionante riprendo il lavoro e provo , grazie ancora .
Buon fine settimana.
Mai mi fu dato di vedere un animale in cordoglio di sé. Un uccelletto cadrà morto di gelo giù dal ramo senza aver provato mai pena per sé stesso.
User avatar
adriano
 
Posts: 108
Joined: 17 Feb 2013, 11:07


Return to BASCOM-AVR

Who is online

Users browsing this forum: No registered users and 7 guests