#avr Logs

Jul 08 2019

#avr Calendar

01:17 AM Maya-sama is now known as Miyu
06:08 AM Kliment: Anyone ever used the internal temp sensor on the attiny 1-series?
06:08 AM LeoNerd: Not yet, but it's on my list of things to fiddle with soon
06:08 AM LeoNerd: I imagine it basically works similar to the older ones on e.g. 328PB, where it's just a different ADC channel
06:10 AM Kliment: I'm trying to read from it, but I keep getting (after conversion) 48 degrees C (which is about twice what it should be) and no response to heat application
06:11 AM LeoNerd: Try printing the raw ADC value as well when you do that, so you can see if that number is changing
06:11 AM LeoNerd: and calculate it yourself
06:16 AM Kliment: I get all-ones
06:16 AM Kliment: for raw reading
06:17 AM LeoNerd: Seems like you've not triggered the ADC properly then
06:18 AM Kliment: I'm doing what the ds says to do
06:18 AM Kliment: ADC0.COMMAND = ADC_STCONV_bm;
06:18 AM Kliment: that should start a conversion, then I wait for conversion to be done (ADC0.INTFLAGS & ADC_RESRDY_bm)
06:19 AM Kliment: then I read ADC0.RES
06:19 AM Kliment: and it's all ones
06:24 AM Kliment: just tried reading another channel, that's all ones too
06:26 AM day: Kliment: connect the adc pin to gnd and see what it reads
06:26 AM day: also, google for some working test code and run that instead of yours
06:30 AM Kliment: day: I tried the atmel start example with same results - all ones
06:30 AM day: well make sure the adc input is tied to a known potential
06:30 AM Kliment: I have a scope on it - it's reading zero
06:31 AM day: do you have anotherone of those µC's?
06:31 AM Kliment: yeah
06:32 AM Kliment: would need to assemble a board though
06:32 AM day: i doubt it is broken, but...
06:32 AM day: i see
06:33 AM Kliment: I'm having difficulty finding working example code for these parts
06:33 AM day: but the 328 is a widespread chip
06:33 AM day: its like the old atmega8
06:33 AM Kliment: day: This is not the 328
06:33 AM Kliment: day: this is the 1-series
06:34 AM Kliment: day: 816/817
06:34 AM day: ah m/b. i read 328PB earlier. after rereading it.... nvm ^^
06:35 AM day: attiny816/7?
06:35 AM Kliment: yeah
06:37 AM day: do you read the register in a loop i.e. multiple times or just once?
06:37 AM day: the first reads are afaik trash
06:37 AM Kliment: just once after conversion
06:37 AM day: first read is*
06:37 AM day: hm
06:38 AM Kliment: as the datasheet and the atmel start code both say you should
06:39 AM day: post your shortest non working code im gonna look at it
06:40 AM Kliment: uitn8_t temp=0; temp=(ADC_0_get_conversion(6))>>2; (voltage on channel 6 is 0, but it reads 0xff)
06:42 AM Kliment: ADC_0_get_conversion is the atmel start implementation: it does ADC0.MUXPOS = channel;ADC0.COMMAND = ADC_STCONV_bm;while(ADC0.INTFLAGS & ADC_RESRDY_bm);res=ADC0.RES;ADC0.INTFLAGS |= ADC_RESRDY_bm;return res;
06:46 AM Kliment: vref is set to 1.1V, resolution is 10bit
06:50 AM day: muxpos == 0x1E?
06:52 AM Kliment: I think I've figured it out
06:53 AM day: so what was the issue?
06:53 AM Kliment: running the ADC too fast
06:53 AM day: eh that sounds fishy
06:53 AM Kliment: speed /2 fails, /8 works
06:53 AM day: hm
06:53 AM Kliment: (prescaler value)
06:53 AM day: just odd that you always got the same result when running it too fast
06:54 AM Kliment: "the ADC requires an input clock frequency between 50kHz and 1.5MHz"
06:55 AM Kliment: makes sense, I was running at 20MHz
06:55 AM day: didnt the official test code not set the prescaler?
06:56 AM Kliment: it sets it to /2
06:56 AM Kliment: which I guess works when running at some other frequency
06:56 AM LeoNerd: I don't have a specific example of the temp sensor but I do have ADC on a tiny814 *generally*, if that's any help to compare
06:56 AM day: thats stupid...why dont they just use the highest divisor. that would always work :P
06:58 AM Kliment: Works now with /16
06:58 AM Kliment: also with temp sensor
07:10 AM Kliment: This is great
07:10 AM Kliment: It's off by about 7-8 degrees from reality
07:10 AM Kliment: but that's it
07:12 AM Kliment: So I'll have to calibrate it (the factory calibration is not that great apparently but this might be because of repeated rework)
07:12 AM Kliment: everything else works great
07:15 AM Kliment: This is the cold point compensation of a thermocouple amp
07:26 AM Kliment: Sadly the ds does not specify any accuracy values for the internal temp sensor
08:38 AM day: Kliment: the sensor is shit tier level bad
08:42 AM LeoNerd: Heh.. it's related to the onboard ADC - of course it'll be bad ;)
08:47 AM Kliment: day: it is, but it's fine for this application - it's reasonably linear, just has some offset
08:47 AM LeoNerd: I'd consider it fine for such purposes as e.g. dynamic fan control, where the exact value probably doesn't matter too much
08:48 AM LeoNerd: I.e. "fan when it's hot, off when it's cool"
08:49 AM Kliment: Here it's to get an ambient temp value inside the handle of the soldering iron
08:50 AM LeoNerd: Mm. yeah if you're controlling a target of 350C to +/- a few C, you probably don't mind if the CJC is off by a few C either
08:53 AM Kliment: exactly
08:55 AM Kliment: Just discovered a super dumb/clever trick to protect the amplifier input from overvoltage
08:55 AM Kliment: I had a zener in there but that would only clamp most of the waveform
08:55 AM Kliment: So I put in an LED
08:56 AM Kliment: clamps perfectly to Vf
08:56 AM LeoNerd: and offers a handy bonus feature of a peak indicator ;)
08:57 AM Kliment: well, it's on whenever the heater is
09:21 AM day: Kliment: yes. if +-10C dont matter and you dont need a fast response time then it may work
09:22 AM day: i know that some led flashlight drivers use the attiny's temp sensor
09:46 AM Kliment: Yeah it's gonna be fine for this application
03:03 PM Emil_ is now known as Emil
03:04 PM Emil is now known as Emil_
03:04 PM Emil__ is now known as Emil
04:28 PM splud is now known as Kavanaugh
04:29 PM Kavanaugh is now known as splud
11:30 PM day__ is now known as day