Attached is the code. I am inputting two ADC channels to a pwm in order to have a variable frequency and duty cycle. The program works except there are these occasional stops for a brief moment. On channel feed OCR1C for the top value and the other adc feeds OCR1A and B for the compare value. I am using both A and B pwm outputs for no particular reason. Could use just one. I suspect it gets hung up slightly when updating or inputting from the TCNT1 register to ADCL and ADCH. Any help would be greatly appreciated.
Thanks in advance
Mod edit: added code tags
Thanks in advance
Code:
.include "tn26def.inc"
.def Ra=r17
.def Rb=r18
.def Rc=r19
.def A=r16
.def I=r20
.def N=r22
.cseg
.org 000
rjmp Reset
Reset:
;Initial I/O
LDI Ra, 0b00000000
OUT DDRA, Ra ;Set port A pin 7 (PA4) to input
LDI Rb, 0b11111111
OUT DDRB, Rb ;Set port B to all output
;Initial PWM
LDI A, 0b01010011
OUT TCCR1A, A ;toggle OC1A and OC1B, reset to $00 OCR1A,B, compare OCRx.
LDI I, 0b00001100
OUT TCCR1B, I ;CK/16384
sei
Main:
;ADC_Init Dwell
ldi Rc,0b00100000
out ADMUX, Rc
ldi Ra, 0b10011011
out ADCSR,Ra
sbi ADCSR,ADSC
Wait:
sbis ADCSR,ADIF
rjmp Wait
NOP
NOP
IN I,ADCL
IN N,ADCH
OUT OCR1A, N ;portB PB0, PB1 connect to PB1 pin
OUT OCR1B, N ;portB PB3, PB2 connect to PB3 pin
;ADC_Init Rate
ldi Rc,0b00100001
out ADMUX, Rc
ldi Ra, 0b10011011
out ADCSR,Ra
sbi ADCSR,ADSC
Wait1:
sbis ADCSR,ADIF
rjmp Wait1
IN I,ADCL
IN Ra, ADCH
OUT OCR1C, Ra
rjmp Main
Last edited by a moderator: