witam , potrzebuję pomnożyć 7razy impulsy wejściowe , częstotliwość wej nie jest duża max 200hz , znalazłem podobny program na pic16 mnożacy 39razy i kawałek kodu na atmege8 również mnożący 39razy , jednak zupełnie nie mam pojęcia jak cos takiego napisac w bascomie
kod dla pic:
a tu kawałek kodu dla atmega8 8mhz w C
kod dla pic:
Device 16F628A
Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_ON
'B0 = VSS input signal = input (pin 6)
'B3 = VSS output signal = output (pin 9)
Dim tm As Word
Dim ttm As DWord
Dim Fout As Word
Dim ovf As Word
tm = 0 ; set counter to 0
ttm = 0
Fout = 0 ; output frequency - 245Hz is lowest possible
ovf = 0
;76543210
PORTB = %00000000 ; all low
TRISB = %00000001 ; 7, 6, 5, 4, 3, 2, 1 en 0 are input (1) or output (0)
INTCON = %11010000 ; Enable interrupts (GIE, PIE, RB0)
T1CON = %00110000 ; setup timer1 with 1:8 prescale (1:2 and 1:4)
PIE1.0 = 1 ; enable tmr1 interrupt
on_interrupt GoTo interrupt_handler
While 1=1
Wend
interrupt_handler:
If INTCON.1 = 1 Then ; VSS pulse came in
T1CON.0 = 0 ; stop counter
tm.LowByte = TMR1L ; read and save counter
tm.HighByte = TMR1H
TMR1H = 0 ; reset counter to 0
TMR1L = 0
T1CON.0 = 1 ; (re)start counter
ttm = tm + (ovf * 65535)
ovf = 0
If ttm > 0 Then
; Fout = 39000000 /(ttm * 8) ; Fout[p/s] = (multiplier / divider[at output]) * 1000000 [us/s] / (cc [p] * 8[p/us])
Fout = 39000000 /(ttm * 2) ; Fout[p/s] = (multiplier / divider[at output]) * 1000000 [us/s] / (cc [p] * 8[p/us]) [with 4 multiplier at output]
If Fout > 245 Then HPWM 1, 127, Fout
EndIf
EndIf
If PIR1.0 = 1 Then ;timer1 interrupt
If ovf < 2 Then ;Because the timer counts a bit fast (thus accurate) we also need to count the overflows
ovf = ovf + 1
Else
T1CON.0 = 0 ;stop counter as the car has stopped (no input VSS pulse within 1,5 seconds)
TMR1H = 0
TMR1L = 0
Fout = 0
ovf =0;
T2CON=%0000000 ; stop hpwm
EndIf
PIR1.0 = 0 ; reset timer interupt flag
EndIf
INTCON = %11010000 ; Reset all interrupt flags
Returna tu kawałek kodu dla atmega8 8mhz w C
interrupt [EXT_INT0] void ext_int0_isr(void)
{
if (ovf>79)
{
if(--licznik<1) licznik=0;
}
else if(ovf<79)
{
if(++licznik>254) licznik=254;
}
ovf=0;
}
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
PORTB.3 = !PORTB.3;
TCNT0=licznik;
ovf++;
}