Ich probier jetzt mal einen pin mit dem timer zu toggeln und speis' den zum Messen ein. Mal schau'n was da gemessen wird.
der code dazu
Alles anzeigen
man erkennt in der Timererklährung, es wird ein Puls von 14,976ms erzeugt.
Die Ausgabe auf dem Terminal ist
Timeout: 0 Impulslänge: 1408 delay: 10
also 1408x10µs= 14,080 ms, passt doch.
Man muss also den timeout auf Basis 1 MHZ rechnen und darauf achten, dass er nicht zu früh die Messung abbricht. Das sind vielleicht deine komischen Effekte ganz am Anfang gewesen
oder diese Ausgabe:
Timeout: 0 Impulslänge: 725 delay: 20
passt auch.
der code dazu
BASCOM-Quellcode
- 'Pulsein.Lib Test
- 'Bascom Version 2.0.8.1
- $regfile = "m328pdef.dat"
- $crystal = 16000000
- $hwstack = 32
- $swstack = 10
- $framesize = 40
- $lib "pulsein.lib"
- Const Cpulsein_timeout = 0
- Const Bpulsein_delay = 10
- Config Pinc.0 = Input
- Config Portc.1 = Output
- const Timer0Reload = 234
- config timer0=timer,prescale = 1024
- load timer0 , Timer0Reload
- on ovf0 Timer0_isr
- enable ovf0
- start timer0
- enable interrupts
- 'Timer value explination
- ' The timer is a 8Bit timer, it overflows when the timer reaches 256
- ' The AVR is running at 16000000Hz, the prescaler is 1024
- ' Each tick is 0,064 ms - (1 / CPUSpeed in KHz ) * Prescaler
- ' The timer needs 234 ticks to reach the required time ( 234 * 0,064 = 14,976ms)
- ' The start value for the timer must be set to 22 so that it will overflow at 256 after 234 ticks
- ' NOTE: The load command does the inversion for you (256-value or 65536-value)
- Dim Impulslaenge_1 As Word
- Do
- Pulsein Impulslaenge_1 , Pinc , 0 , 1
- Print "Timeout: " ; Cpulsein_timeout ; " Impulslänge: " ; Impulslaenge_1 ; " delay: " ; Bpulsein_delay
- Wait 1
- Loop
- End
- Timer0_isr:
- Load Timer0 , Timer0reload
- Toggle Portc.1
- Return
Die Ausgabe auf dem Terminal ist
Timeout: 0 Impulslänge: 1408 delay: 10
also 1408x10µs= 14,080 ms, passt doch.
Man muss also den timeout auf Basis 1 MHZ rechnen und darauf achten, dass er nicht zu früh die Messung abbricht. Das sind vielleicht deine komischen Effekte ganz am Anfang gewesen
oder diese Ausgabe:
Timeout: 0 Impulslänge: 725 delay: 20
passt auch.
Raum für Notizen
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von tschoeatsch ()