#avr Logs

Jul 30 2017

#avr Calendar

12:03 AM day is now known as daey
02:07 AM rue_shop3: I got soe t85, but then found out they dont have a uart
02:07 AM rue_shop3: either
02:15 AM JanC is now known as Guest4059
03:30 AM Emil: sure they do
03:31 AM Emil: "sorta"
12:36 PM capu: hey guys, i need some help programming an AVR with avr-gcc. I've read the documentations about DDRC, PORTC and PINC. I want to let a led blink on just 1 of the port c pins. But still not really getting it done... does someone have a clear example how to make just 1 pin from PORTC as output ?
12:37 PM tpw_rules: set the bit in PORTC corresponding to the pin you want
12:38 PM tpw_rules: i mean DDRC
12:38 PM tpw_rules: like DDRC = (1 << 4); to set pin 4 in port C as output. note that they start from 0
12:40 PM tpw_rules: which would be pin 27 on a DIP ATMEGA328P
12:47 PM capu: tpw_rules, that works! Thanks. why doesn't this work when DDRC = 0xFF; and PORTC != (1<<4) ??
12:47 PM capu: | instead of !
12:47 PM tpw_rules: that turns all pins to outputs
12:48 PM tpw_rules: so the ones which aren't set 1 by portc get grounded
12:51 PM capu: ok for instance, if i want to use PC5 for input and 4 for output. How is that done together?
12:52 PM capu: DDRC = ((1<<4) | (0<<5)) ??
12:52 PM Tom_itx: http://tom-itx.no-ip.biz:81/~webpage/how_to/atmega168/mega168_led_blink_delay_index.php
12:52 PM capu: i' ve read i need to use the PIN registers for inputs
12:53 PM tpw_rules: capu: the DDR register holds the current direction of the pin. 0 for input, 1 for output
12:53 PM tpw_rules: if the DDR for a pin is 1, the PORT bit for that pin controls if it's driven high or low. if DDR for a pin is 0, the PORT bit controls whether the pullup is activated (1 = activated). the PIN bit contains the input value for that pin
12:54 PM tpw_rules: so you set DDR to 0 and read the bit from PIN to see if the pin was on or not
12:59 PM Emil: capu: https://emil.fi/avr
01:00 PM capu: https://pastebin.com/QKrC5Bay
01:00 PM capu: can i do that ?
01:01 PM Emil: matey
01:01 PM capu: im reading your link Emil
01:01 PM Emil: like a variable, registers hold a value
01:02 PM Emil: when you do DDRC=(1<<4); it is the same as doing DDRC=0b0010000;
01:02 PM Emil: which is the same as doing DDRC=16;
01:21 PM Emil: capu: did you succeed?
01:26 PM capu: hm, im having a new compile problem atm.
01:26 PM capu: i removed the blink.elf which i used to make blink.hex, but when i recompile the blink.c it doesn't make the .elf anymore
01:27 PM capu: avr-gcc -g -Os -mmcu=atmega328p -c blink.c -DF_CPU=8000000UL
01:28 PM Emil: ...
01:29 PM Emil: You should check the commands I have listed
01:29 PM Emil: And how yours differs
01:30 PM capu: i see! yeah that works
01:47 PM capu: okay i dont really understand the exact meaning of 0b00000001
01:47 PM capu: i found PC1 or PC4 easier :p
01:50 PM Emil: 1<<4==0b00010000;
01:50 PM Emil: You should use PC4 and so on
01:51 PM Emil: PC4 is a define like #define PC4 4
01:51 PM Emil: And when you do 1<<4 you get 0b00010000
02:09 PM capu: https://pastebin.com/Nv0DQESz your code works perfectly Emil. I'm trying to do something else, i connected a button to PC2 and a led to PB0 with this code
02:09 PM capu: but the led doesnt go on when i press the button
02:21 PM Emil: capu: a) what does |= do?
02:22 PM Emil: oh you just want to turn it on
02:22 PM Emil: capu: how does your button connect?
02:23 PM capu: +5V to the button on one end, and from the button on the other end to PC2
02:23 PM capu: and also a 10k resistor on PC2 to GND
02:23 PM Emil: alrighty, that sounds good
02:23 PM capu: PB0 to + LED, - LED to GND
02:23 PM Emil: capu: is your led the righ way on?
02:23 PM Emil: capu: umm
02:24 PM Emil: capu: you do have a resistor there, too?
02:24 PM capu: the long side is the + i guess right
02:24 PM Emil: you _need_ a resistor with the led
02:24 PM capu: no resistor... doesn't really need it
02:24 PM Emil: ayyyy
02:24 PM Emil: well, your mcu might be broken then
02:24 PM capu: let me try
02:24 PM capu: cuz i connected the led to +5 and GND directly and it turns on perfectly
02:24 PM Emil: And the likelyhood of you breaking it by not having a resistor there
02:25 PM Emil: it's high
02:25 PM Lambda_Aurigae: doesn't....need...it...
02:25 PM Lambda_Aurigae: what makes you think you don't need a current limiting resistor on an LED being fed from a microcontroller i/o pin?
02:26 PM Emil: it might have a builtin resistor if he can connect it to 5v and gnd directly
02:26 PM capu: because i connected it to the +5 pins before without resistor. And also connected it tp PC4 for a few mins directly to gnd without probs..
02:26 PM capu: so why not PB0 ?
02:26 PM Lambda_Aurigae: dude
02:26 PM Emil: capu: connect the led to 5v and gnd
02:26 PM Emil: and let it stay there
02:26 PM capu: loll
02:26 PM Lambda_Aurigae: you might have drawn waaaay too much current through that i/o pin.
02:27 PM Lambda_Aurigae: always always always ALWAYS use a current limiting resistor on LEDs
02:27 PM capu: okay, my bad then
02:27 PM Emil: I said the same thing 3 minutes ago
02:28 PM Lambda_Aurigae: read Getting Started In Electronics before ever picking up an LED or battery, please?
02:28 PM capu: usually a 220 ohm is sufficient for a led right?
02:28 PM Lambda_Aurigae: I use 330ohm myself, but that's because I have a couple thousand of them on a reel.
02:28 PM Emil: capu: yeah
02:28 PM Lambda_Aurigae: for one LED, it should work.
02:28 PM Emil: I use 1k quite often
02:29 PM Emil: It's a nice power of ten figure
02:29 PM Lambda_Aurigae: if you have multiple LEDs on an AVR, you might want to watch total current draw per pin, per port, and per chip.
02:29 PM Lambda_Aurigae: and read the datasheet.
02:30 PM Lambda_Aurigae: also depends on whether you are using 5V or 3.3V for VCC and how bright you want the LED and the specs on the LED itself.
02:31 PM Lambda_Aurigae: white, blue, green, red, yellow all have different specifications and would require different resistors to give the same relative brightness at a given voltage...and will draw different amounts of current as well.
02:31 PM Lambda_Aurigae: and even different LEDs of the same color.
02:32 PM Lambda_Aurigae: that being said, something in the 220ohm to 2.2K ohm range usually works for most things.
02:34 PM capu: does every pin a chip have a different output voltage?
02:34 PM Emil: wat
02:35 PM capu: does every pin on a microcontroller has a different output voltage when turned on?
02:36 PM Tom_itx: no
02:36 PM Lambda_Aurigae: no
02:36 PM Lambda_Aurigae: but there is a total chip current capacity, a port total current capacity, and a pin current capacity limit.
02:36 PM Emil: Yeah sounds like you broke your thing
02:37 PM capu: hm
02:37 PM capu: i have a couple more atmega328s if its broken
02:38 PM capu: i connected the led with a 220 ohm resistor and reprogrammed the DDRD to PD7 as output (thats 1 pin higher than the PB0 on the left)
02:38 PM capu: but still nothing
02:40 PM Lambda_Aurigae: ok...so, set all the i/o pins to output.
02:40 PM Lambda_Aurigae: then hook LED to each pin and see what happens.
02:40 PM Lambda_Aurigae: make sure you use a resistor...and,,try reversing the LED
02:40 PM Lambda_Aurigae: make sure the pins are set to output and set to HIGH.
02:40 PM Tom_itx: capu, you just trying to get an led to blink?
02:41 PM Tom_itx: http://tom-itx.no-ip.biz:81/~webpage/how_to/atmega168/mega168_howto_main_index.php
02:41 PM capu: jup
02:41 PM Tom_itx: that will get you that
02:41 PM capu: works!!
02:41 PM capu: so the problem is with the button or the code
02:41 PM Lambda_Aurigae: so test the button
02:42 PM Tom_itx: http://tom-itx.no-ip.biz:81/~webpage/how_to/atmega168/mega168_led_blink_delay_index.php
02:44 PM capu: i checked out your website Tom, it has a tutorial about interrupts. will follow that later. I got the leds blinking before
02:45 PM capu: im just trying to mix inputs with outputs using a button
02:48 PM capu: when i connect the button directly to the led, it just works
02:48 PM capu: so the question, whats wrong wit this: if((PINC & (1<<PC2)) == 1)
02:49 PM Lambda_Aurigae: hahahaha!
02:49 PM Emil: because
02:49 PM capu: i set DDRC = (1<<PC2)
02:49 PM Lambda_Aurigae: what is PC2?
02:49 PM Emil: that's not one
02:49 PM Lambda_Aurigae: PC2 = 2
02:49 PM Emil: what is 1<<PC2
02:49 PM Lambda_Aurigae: so, 1<<PC2 = 0x00000100
02:50 PM Emil: >0x
02:50 PM Emil: You sure about that
02:50 PM Emil: How about 0b ;)
02:50 PM Lambda_Aurigae: no
02:50 PM Lambda_Aurigae: I never use the whole PC2 thing myself anyhow.
02:50 PM Lambda_Aurigae: I just use real numbers.
02:51 PM Lambda_Aurigae: guh...wouldn't be 0x...would be 0b
02:51 PM Emil: 1<<PC2==0b00000100
02:51 PM Lambda_Aurigae: it's been a strange day.
02:51 PM Lambda_Aurigae: so I goofed..sorry.
02:51 PM Lambda_Aurigae: anyhow,,,
02:51 PM capu: ehh, you are talking about the 1<<PC2 ? == 1 stands for boolean high i guess
02:51 PM capu: haha
02:51 PM Lambda_Aurigae: if pin 2 of port c is high then PINC will be 0b00000100
02:51 PM Emil: capu: this is why you don't test against 1
02:52 PM Emil: you just test if it's something else than 0
02:52 PM capu: let me be honest, i thought (1<< PC2) makes it an output
02:52 PM Emil: so if(PINC&(1<<PC2))
02:52 PM Lambda_Aurigae: so, 0b00000100 & 0b00000100 will never equal 1
02:52 PM capu: ooh
02:52 PM Lambda_Aurigae: it will equal 4
02:53 PM Lambda_Aurigae: now, if you change that & to &&, that might work.
02:53 PM Lambda_Aurigae: but as you are doing a math & rather than logic &&, it's totally different output.
02:53 PM Emil: Lambda_Aurigae: please
02:54 PM Emil: Lambda_Aurigae: no
02:54 PM Emil: no &&
02:54 PM Emil: it would trigger on any pin
02:54 PM Lambda_Aurigae: I said might.
02:54 PM Emil: You dirty old man trying to trick newbiew like that
02:54 PM Emil: :D
02:54 PM Lambda_Aurigae: of course.
02:54 PM Lambda_Aurigae: lessons learned the hard way are better remembered.
02:55 PM Lambda_Aurigae: that, and, I'm a bastard.
03:03 PM capu: im giving up for today
03:10 PM antto: Lambda_Aurigae u bstrd!
03:12 PM Jartza: allo
03:14 PM Emil: Hngh, I have no interest in manually calculating shit why is this course pretty much only about that
03:14 PM Emil: I understand the concepts just fine
03:15 PM antto: there are a few bots on freenode which can compile and evaluate short snippets of code quickly
03:15 PM antto: in case anyone didn't know
03:16 PM antto: highly useful!
03:18 PM Emil: yeah
03:20 PM antto: next, there's a few websites like cpp.sh
03:56 PM polprog: theres compilebot on reddit
03:56 PM polprog: also
04:50 PM Emil: >Deadline at 23:55
04:50 PM Emil: >Attempt to return work at 23:31
04:50 PM Emil: >Submission box doesn't work so send an email to ta with submission
04:51 PM Emil: >Look at phone
04:51 PM Emil: >MFW Winshit is literally 40 minutes late for no apparent reason in time
04:51 PM polprog: savage
04:51 PM polprog: >not using linux with NTP
04:52 PM Emil: Linux still has that same fucking issue unless you manually change the config
04:52 PM Emil: But this is ridiculous, I don't understand how this could have happened :D
04:52 PM Emil: Ohwell, I'll beg for some points from the head ta
04:54 PM polprog: the real fun starts when you have your RTC set in different timezone
04:56 PM Emil: or when there's errata on RTCs...
04:57 PM polprog: goodnight
04:57 PM Emil: Goodnight
05:12 PM absynth is now known as dan2wik
07:24 PM Jartza: https://www.youtube.com/c/JariTulilahti/live
07:24 PM Jartza: wanna try?
07:45 PM robinak is now known as robink
08:11 PM Jartza: back online, now with manual focus and better colors :)
08:28 PM Jartza: https://www.youtube.com/c/JariTulilahti/live