#avr Logs

Sep 13 2021

#avr Calendar

02:30 AM specing_ is now known as specing
04:35 AM exp: nohit: if you just want to add assembler to your C, write .S files and include them? if you want to make a faster function, use inline asm?
04:36 AM nohit: why are you telling me this
04:36 AM exp: oh sorry, i mistook nohit and nero :)
04:36 AM exp: morning eyes
04:37 AM nero: i used inline asm for specialized functions
04:38 AM nero: but i was looking for tooling to have a bare asm build
04:38 AM exp: well all of the gnu tooling will do that, because it already does in a way
04:38 AM nero: ngl, since im writing an assembler for 8086 anyways, i guess will just add a port to avr
04:38 AM exp: but i'm not sure i really see the point
04:38 AM exp: you'll just end up reimplementing the C preamble
04:38 AM nero: somewhat
04:39 AM nero: asm also offers some freedoms that are not possible with C
04:39 AM exp: you can save a few cycles here and there for sure
04:39 AM nero: also use a number of stacks different from 1
04:39 AM exp: best of luck in an avr with ~1k memory ;-)
04:39 AM exp: but sure
04:40 AM nero: the "multiple state machines" scenario is a case where multiple stacks are useful
04:40 AM nero: with each SM's state is stored as one or several return address on the stack
04:41 AM exp: there are lots of impressive and useful things you can do with assembler
04:41 AM exp: it's just very rarely worth the tradeoff IMO
04:42 AM nero: "worth" is subjective. i got a knack for assembly
04:44 AM exp: indeed it's very subjective
04:44 AM exp: but it's a question of effort for reward
04:44 AM exp: hence why i tend to keep C around
04:45 AM exp: I understand your perspective completely, and have no argument with it :D
06:24 AM amahl: got attiny13 thats supposed to generate 50 Hz square wave with varying duty cycle between 7.5% and 10%. ideally would like to finely adjust duty cycle with an 8-bit variable. not sure which timer mode/prescaler/interrupt configuration would let me do it most accurately
06:29 AM exp: how finely is 'finely'? what other restrictions do you have?
06:53 AM amahl: theres a motor controller that accepts said square wave. to adjust motor speed the on-time should be varied between 1500 and 2000 us. so 500 us window. 'finely' would mean in ~5 us steps (~100 steps total). meanwhile the off-time is 20 ms. I don't see how to achive this with an 8-bit timer
06:55 AM amahl: maybe just generate an interrupt every 5 us. but if F_CPU = 8 Mhz (only have internal oscillator) then the interrupt would fire every 40 cycles which is just nonsense
06:56 AM amahl: or maybe I could set up the interrupt to generate on-pulse, then set it up again to generate longer off-pulse. this code gets complicated
06:57 AM amahl: need different prescalers for finely controlling the length of both on and off time
07:09 AM exp: amahl: sorry i had to go AFK
07:09 AM exp: there's no reason you can't bit-bang the 50hz part
07:09 AM exp: and use the timer for your 500µS window
07:10 AM exp: you can do the lazy thing and just count its overflows for 50hz, it depends what jitter you can accept
07:34 AM amahl: ah yes
07:38 AM sabor: you just have to change the generated PWM in an interrupt, 100%, 100%, 42%, 0%, 0%, ..., 0%, 100%
07:38 AM sabor: the difficulty is to be able to generate both, 100% and 0%
07:42 AM amahl: yes. annoyingly attiny13 only has one timer
07:43 AM LeoNerd: timer to trigger, CPU busywait count for duration?
07:44 AM amahl: I try CTC mode, clear on compare match, then using overflow interrupt to get 50 Hz, like exp said
07:44 AM LeoNerd: If you're not doing anything else at the time
07:44 AM exp: amahl: if you only need 100 steps you can also clock it down slightly
07:44 AM amahl: can't busywait because its also bit-banging stuff to LCD
07:44 AM exp: i don't know the details of the prescaler, but you can likely also flip that between cycles to avoid triggering 160000 useless interrupts
07:46 AM amahl: I think so? should be possible to set prescaler at any time?
07:46 AM exp: it's more the number of cycles it takes effect in
07:46 AM exp: you'll just need to be careful to avoid accidentally offsetting or adding jitter
07:48 AM exp: so, if you're using an 8mhz clock, you need 256 counts ideally over 2ms, the prescaler doesn't have the accuracy to get this dead on
07:48 AM exp: so you're going to have to use both overflow and compare interrupts
07:49 AM exp: the equivalent of 100 steps seems doable though, i don't have the energy to do the maths correctly :-)
07:50 AM amahl: prescaler=64 only gives accuracy of 8 us. so 62.5 steps. kinda crap but I'll take it
07:51 AM amahl: next time I better pick a MCU with a 16-bit counter
07:52 AM exp: the number of interrupts here is still quite low
07:52 AM exp: you're doing one every 16384 cycles at 64
07:52 AM exp: so emulating a 16 bit timer is no problem at all
07:53 AM exp: this is only during the active period too, and if you're bit-banging to LCD I bet the timing requirements there are broad
08:00 AM amahl: gotta first test how sensitive the motor controller is to the correct timing
02:30 PM specing_ is now known as specing