I will try to provide the most info, in order someone to help me with this little problem...
I'm using attiny13 in order to measure small changes
at a voltage level around 3,578 Volt.
The pin used is PB4 (ADC2) and is driven through a
resistor network (voltage divider by approx.3)
The input of the voltage divider is from transformer
9V, diode bridge, Capacitor filter (100uF).
When used on wall outlet without the tiny13,
i setup the voltage on PB4 to be around 3,578 V (so
223 Volt AC on the outlet). When inserting the
tiny13 on the circuit, it's doesn't work as i want
and many times gives an up / down sequence, but when
i measure the input voltage on PB4 is far away my setup point (around 2,95 V)
The PB0 and PB1 are setup according to the:
PB1 PB0 1 1 -> AC between 215V (3,497) and 225V (3,660) 0 0 -> AC between 215V (3,497) and 225V (3,660) 0 1 -> AC lower than 215V 1 0 -> AC higher than 225V
The tiny13 ADC is clocked by internal 4,8MHz
The setup for the PORTB (i have equed the PBx ports
in the header file, instead using PORTBx, PINBx)
ldi genio, (1<<PUD) (with genio = r16) out MCUCR, genio Disable Pull-ups (but the same problem is occured and with pull-ups enabled) ldi genio, 0b100111 ; PB4,3=In (ADC),PB5,PB2-0 = OUT out DDRB, genio ldi genio, 0b000100 ; Startup values / No pullups out PORTB, genio ; PB2 is used as "operating Led"
The watchdog is not used, turned off as described on
the datasheet ot the tiny13
The Setup for ADC:
ldi genio, (1<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIE) | (1<<ADPS2) | (1<<ADPS1) | (0<<ADPS0) out ADCSRA, genio
With Prescaler = 64, ADC Clock = 4,8Mhz/64=75kHz
Channel and Reference
ldi genio, (0<<ADLAR) | (0<<REFS0) | (1<<MUX1) | (0<<MUX0) out ADMUX, genio
Vcc=5V as ref., no left adjust, channel=ADC2/PB4
Start a conversion and wait until completed:
sbi ADCSRA, ADSC nop WaitADC: sbis ADCSRA, ADIF rjmp WaitADC
After conversion completed, i get the values:
in ResLo, ADCL (ResLo = r17) in ResHi, ADCH (ResHi = r18)
My desired values are between $2CC and $2EE with
the value $2DD being for the 220V output
(about 3,578 to the PB4 pin)
I created a table for the 10-bit analysis of 5V
and found the above values (approx.)
So $2CC = 716decimal and $2EE = 750dec approx.
The checking routine to decide what to do...
(The label ToReturn Jumps to Main Program
after a small delay ~ 5ms)
cpi ResHi, 2 breq CheckLevels cpi ResHi,3 breq isHigher cpi ResHi, 1 breq isLower CheckLevels: cpi ResLo, $CC brlo isLower cpi ResLo, $DD brsh isHigher ;If not jumped on CheckLevels, we are between, so OK sbi PORTB, PB0 sbi PORTB, PB1 rjmp ToReturn isLower: sbi PORTB, PB0 cbi PORTB, PB1 rjmp ToReturn isHigher: cbi PORTB, PB0 sbi PORTB, PB1
The PB0 and PB1 are read by a AT90S2313 MCU
and according to the states, lights the
corresponing Led and chenges the driving
sequence for the rest of the circuit
My problem is that the voltage measured on PB4
is not as it had to be, and even worse
when the output goes higher (i.e 230V)
the PB4 pin and so the tiny13 still has less
than what it should be (i.e 3,205 V instead of 3,990)
Do you see any software problem?
Any help wold be very much aprreciated
Thanks in Advance
[some code tags added - moderator]