Напишите как правильно в Баскоме использовать АЦП с режимом Noise Canceler?
Просьба не тыкать в мануалы, даташит и книги. Смотрел, искал, читал. Но ничего не понял. Лучше код с объяснением что, почему и как.
Спасибо.
Код: Выделить всё
$regfile = "m8adef.dat"
$crystal = 11059200
$baud = 19200
Config Adc = Single , Prescaler = Auto , Reference = Avcc
On Adc Adc_int
Config Portd.2 = Input
Set Portd.2
Dim Vol As Word
Vol = 0
Config Int0 = Falling
On Int0 Button
Enable Interrupts
Enable Int0
Do
Print Vol
Loop
Adc_int:
Vol = Getadc(0)
Config Powermode = Adcnoise
Return
Button:
Print "Button!"
Waitms 500
Gifr = 64
Return
EndА как помочь, если Вы единственный путь отрубили на корню ? :Stass48 писал(а):Неужели никто не хочет помочь?
Stass48 писал(а):Просьба не тыкать в мануалы, даташит и книги.
Код: Выделить всё
' ADC_INT.BAS
' demonstration of GETADC() function in combintion with the idle mode
' for a better noise immunity
' Getadc() will also work for other AVR chips that have an ADC converter
'--------------------------------------------------------------------
$regfile = "4433def.dat"
$crystal = 4000000
$baud = 19200
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function
'The prescaler divides the internal clock by 2,4,8,15,32,64 or 128
'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible
Config Adc = Single , Prescaler = Auto
'Now give power to the chip
On Adc Adc_isr Nosave
Enable Adc
Enable Interrupts
Dim W As Word , Channel As Byte
Channel = 0
'now read A/D value from channel 0
Do
Channel = 0
'idle will put the micro into sleep.
'an interrupt will wake the micro.
Start Adc
Idle
Stop Adc
Print "Channel " ; Channel ; " value " ; W
Waitms 500
Loop
End
Adc_isr:
push r24
in r24,sreg
push r24
push r25
W = Getadc(channel)
pop r25
pop r24
!out sreg,r24
pop r24
Return
'The new M163 has options for the reference voltage
'For this chip you can use the additional param :
'Config Adc = Single , Prescaler = Auto, Reference = Internal
'The reference param may be :
'OFF : AREF, internal reference turned off
'AVCC : AVCC, with external capacitor at AREF pin
'INTERNAL : Internal 2.56 voltage reference with external capacitor ar AREF pin
'Using the additional param on chip that do not have the internal reference will have no effect.Код: Выделить всё
$regfile = "m8adef.dat"
$crystal = 11059200
$baud = 19200
Config Adc = Single , Prescaler = Auto , Reference = Avcc
On Adc Adc_int Nosave
Enable Adc
Enable Interrupts
Dim Vol As Word
Do
Start Adc
Config Powermode = Adcnoise
Stop Adc
Print Vol
Waitms 500
Loop
Adc_int:
push r24
in r24,sreg
push r24
push r25
Vol = Getadc(0)
pop r25
pop r24
!out sreg,r24
pop r24
Return
EndКод: Выделить всё
$regfile = "m8adef.dat"
$crystal = 11059200
$baud = 19200
Config Portd.2 = Input
Set Portd.2
Config Int0 = Falling
On Int0 Mode_sub
Enable Int0
Config Adc = Single , Prescaler = Auto , Reference = Avcc
On Adc Get_adc
Enable Adc
Dim Vol As Word , Vol_buff As Word
Dim Round_pl As Word , Round_min As Word , Round_val As Byte
Vol = 0
Vol_buff = 0
Round_val = 1
Enable Interrupts
Do
Start Adc
Config Powermode = Adcnoise
Stop Adc
Round_pl = Vol + Round_val
Round_min = Vol - Round_val
If Vol <> Vol_buff And Round_pl <> Vol_buff And Round_min <> Vol_buff Then
Vol_buff = Vol
Print Vol
Waitms 100
End If
Loop
Mode_sub:
Print "ch_mode"
Waitms 500
Gifr = 64
Return
Get_adc:
Vol = Getadc(0)
Return
EndКод: Выделить всё
'--------------------------------------------------------------------
' ADC_INT.BAS
' demonstration of GETADC() function in combintion with the idle mode
' for a better noise immunity
' Getadc() will also work for other AVR chips that have an ADC converter
'--------------------------------------------------------------------
$regfile = "m88def.dat"
$crystal = 8000000
$baud = 19200
$hwstack = 40
$swstack = 8
$framesize = 40
Declare Sub Adc_isr()
'configure single mode and auto prescaler setting
'The single mode must be used with the GETADC() function
'The prescaler divides the internal clock by 2,4,8,16,32,64 or 128
'Because the ADC needs a clock from 50-200 KHz
'The AUTO feature, will select the highest clockrate possible
Config Adc = Free , Prescaler = Auto , Reference = Internal
'Now give power to the chip
On Adc Adc_isr Nosave
Enable Adc
Enable Interrupts
Dim W As Word , Channel As Byte
Channel = 0
'now read A/D value from channel 0
Do
Channel = 0
'idle will put the micro into sleep.
'an interrupt will wake the micro.
Start Adc
Idle
Stop Adc
Print "Channel " ; Channel ; " value " ; W
Loop
End
Sub Adc_isr()
$asm
push r26
push r27
push r24
in r24,SREG
push r24
push r25
$end Asm
W = Getadc(channel)
$asm
pop r25
pop r24
Out Sreg , R24
pop r24
pop r27
pop r26
$end Asm
End SubОгромное Вам Человеческое Благодарю, за Вашу помощь в другой веткеroman.com писал(а):Ух... вот бы с удовольствием помог хорошему Человеку...
Ну все же не совсем так. В обработчике прерывания регистры общего назначения могут использоваться под свои нужды, и может случиться так, что будут затерты нужные данные, включая статусный регистр SREG. Потому SREG и все РОН сохраняются в стек в самом начале обработчика, и извлекаются из стека в конце оного.kip96 писал(а):При прерывании теряете все переменные(данные)
Код: Выделить всё
$asm
push r26
push r27
push r24
in r24,SREG
push r24
push r25
$end Asm
.........
$asm
pop r25
pop r24
Out Sreg , R24
pop r24
pop r27
pop r26
$end Asm
Точнее, все РОН, используемые в данном обработчике . Уж такой я буквоед ...edm2007 писал(а): все РОН сохраняются в стек
Ну это да, такие важные мелочи упускать нельзя.Jack_A писал(а):Точнее, все РОН, используемые в данном обработчике . Уж такой я буквоед ...
Код: Выделить всё
$regfile = "m8def.dat"
$crystal = 4000000
Config Int0 = Falling
On Int0 Button
Enable Interrupts
Enable Int0
'------------------------------------------
Do
Loop
'------------------------------------------
Button:
Return
Ну так за одно это всякие тому подобные компиляторы, генерящие бездумную кучу кода, стоит заткнуть в одно место. Ну если только новичку помигать диодами. Страшно представить, если на таком @#$% напишут что-то вроде защиты ЛЭП или самозапуска электродвигателя . Я так думаю.edm2007 писал(а): без Nosave всегда сохраняются эти регистры, даже если обработчик совершенно пустой.
When you omit NOSAVE all used registers will be saved. These are SREG , R31 to R16 and R11 to R0 with exception of R6,R8 and R9 .
R12 – R15 are not saved.
Код: Выделить всё
$regfile = "attiny2313.dat"
$crystal = 8000000
Dim Mine As Byte
Dim Hour As Byte
Dim Seco As Byte
Config Portb.0 = Output ' подключен светодиод
Config Sda = Portd.5 ' подключение DS1307
Config Scl = Portd.4
Config Pind.0 = Input
Config Pind.1 = Input
Pinb.0 = 1
Hour = 0
Mine = 0
Do
I2cstart
I2cwbyte &HD0
I2cwbyte &H00
I2cstart
I2cwbyte &HD1
I2crbyte Seco , Ack
I2crbyte Mine , Ack
I2crbyte Hour , Nack
I2cstop
Seco = Makedec(seco)
Mine = Makedec(mine)
Hour = Makedec(hour)
If Seco = 5 Then
Pinb.0 = 0
Else
Pinb.0 = 1
End If
Waitms 100
Loop
EndКод: Выделить всё
Chek1:
!lds r16,{Sleep_byte} 'If Sleep_byte = 1 Then Goto Sleep_call
!cpi r16,1
!brne tm101
!ldi ZL , low(Sleep_call) ' Забираем адрес метки
!ldi ZH , high(Sleep_call) ' Забираем адрес метки
!ijmp ' Переход на метку без последствий для стека
Tm101:
ReturnКод: Выделить всё
Sleep_call:
Set Pwr_on1 'выключаем дисплей
Set Pwr_on 'выключаем RTC (время)
Stop Timer2 '
Config Timer2 = Counter , Async = On , Prescale = 1024 '(переконфигурируем Timer2 на переполнение 9сек)
Start Timer2
Do
Gosub Chek 'Обработчик прерывания
!SBIC pina,7 'Проверка подключения зарядки
!jmp k1
!lds r16,{Ok_key} 'Просыпаемся от нажатия комбинации клавишь (up_key и ok_key)
!lds r17,{Up_key} 'Кнопки завязаны с INT0 и INT1
!cpi r16,0
!brne s1
!cpi r17,0
!brne s1
K1:
Gosub Wake_up 'Подпрограмма просыпания
!ldi r16,1
!sts {ok_key},r16
!sts {up_key},r16
!jmp Main ' УХОД В ГЛАВНОЕ, НАЧАЛЬНОЕ ОКНО ПРОГРАММЫ (НАЧАЛО)
S1: 'End If
!ldi r16,1
!sts {ok_key},r16
!sts {up_key},r16
Power Powersave
LoopКод: Выделить всё
Wake_up: 'Тут мы просыпаемся
Waitms 1
Reset Pwr_on1 'Включаем питание дисплея
Reset Pwr_on 'Включаем питание RTC
Waitms 1
Config Graphlcd = Custom , Cols = 128 , Rows = 64 , Lcdname = "SSD1306"
Lcd_auto = 0
Initlcd 'Инициализируем LCD
Waitms 300
Stop Timer2
Config Timer2 = Timer , Async = On , Prescale = 64 '(переконфигурируем Timer2 на переполнение 0.5сек)
Start Timer2
Return