#avr Logs

Oct 12 2017

#avr Calendar

09:02 AM remkooo1 is now known as remkooo
09:14 AM Gerritjan: hello all
09:14 AM Gerritjan: can i do with a while like a 2ms run or is there a better way?
09:19 AM _ami_: Gerritjan: what do u mean about 2ms run?
09:19 AM Gerritjan: while loop
09:20 AM Gerritjan: because i need like 2ms readings from a digital gpio
09:20 AM _ami_: so you want to run while loop for 2ms ?
09:20 AM Gerritjan: yes
09:21 AM _ami_: well. you can run a timer and set it to call ISR on every 2ms and read the gpio in timer isr
09:22 AM _ami_: or you can have a flag say timeToReadGPIO, which u set to true in timer isr
09:22 AM Gerritjan: well im using now a interrupt on the gpio so im getting only the info when its activated now i need loop when its activated for 2 or more ms information
09:23 AM Gerritjan: im using bcm2835 lib
09:24 AM _ami_: you could start the timer when get the interrupt and keep checking mainloop until timer is expired
09:25 AM Gerritjan: im trying now something with steadyclock
09:25 AM _ami_: what is steady clock?
09:26 AM _ami_: is it a lib name?
09:26 AM Gerritjan: yes from chrono
09:26 AM _ami_: lol. chrono :P
09:27 AM Gerritjan: yes
09:27 AM _ami_: dude, are you using C++ on PC? or on AVR? :)
09:27 AM Lambda_Aurigae: sounds like an ardweeny thing
09:27 AM Gerritjan: rpi
09:27 AM _ami_: wtf, - its an AVR channel - not rpi
09:27 AM Gerritjan: oke sorry
09:28 AM Gerritjan: but it has also gpio pins :
09:28 AM Gerritjan: :D
09:28 AM _ami_: AVR is a 8 bit MCU
09:28 AM _ami_: lol
09:28 AM Gerritjan: i know i hve them to :D
09:28 AM _ami_: i should have guessed it when you mention bcm lib
09:28 AM _ami_: damn
09:28 AM Lambda_Aurigae: totally different platform, totally different system for doing just about everything.
09:29 AM polprog: lol
09:29 AM Gerritjan: oke ill will not ask here something any more about rpi or somethinh else
09:29 AM Lambda_Aurigae: like asking motorcycle guys how to rebuild a hyundai engine
09:30 AM Gerritjan: well they dont have any trouble with it :D
09:30 AM _ami_: no, we have no problem in asking non-avr stuffs... but you have to provide more informations
09:30 AM _ami_: (22:43:31) Gerritjan: can i do with a while like a 2ms run or is there a better way? --> e.g. is this a complete question?
09:31 AM _ami_: you have used "while" ->
09:31 AM Gerritjan: yes
09:31 AM _ami_: did not give any information on which platform are you trying
09:31 AM _ami_: Gerritjan: what is "while"?
09:31 AM Gerritjan: while(steady_clock::now - start < milliseconds(2)){}
09:31 AM _ami_: oh boy!
09:31 AM _ami_: how old are you?
09:31 AM Gerritjan: to old :D
09:32 AM polprog: that loop makes no sense
09:32 AM _ami_: did you share this code before? no.
09:32 AM _ami_: humans are not mind readers
09:33 AM rue_mohr: do you just want a 2ms delay?
09:33 AM _ami_: rue_mohr: he is coding for rpi
09:33 AM rue_mohr: ok
09:33 AM rue_mohr: delay?
09:34 AM Gerritjan: no a run for 2 seconds
09:34 AM Lambda_Aurigae: on avr, I would use interrupt on pin to start timer...and interrupt on pin going low to stop and read timer and check for 2ms delay.
09:35 AM polprog: it's possible to fix that loop by storing steady_clock::now in a variable and comparing the variable in the while condition. dont take my word for it, never used that library
09:35 AM rue_mohr: for(killtime = time() + 2; time() < killtime; ) { }
09:36 AM polprog: thats even better
09:36 AM rue_mohr: time() gives epoch in milliseconds, right?
09:36 AM rue_mohr: hmm, seconds isn't it?
09:36 AM Gerritjan: no 2ms
09:36 AM polprog: epoch in linux is generally sotred in seconds
09:36 AM polprog: stored*
09:37 AM rue_mohr: time() is seconds..
09:37 AM Gerritjan: but i need to collect from a sound detection module the pulse thats why i need like 2ms of data
09:37 AM rue_mohr: how many samples in 2ms?
09:37 AM Gerritjan: unknown
09:38 AM rue_mohr: there has to be a sample rate...
09:38 AM Gerritjan: sometimes i got like 2407 and it can be like 2070hz
09:39 AM rue_mohr: heh, not just grabbing adc values as fast as you can, right?
09:39 AM Gerritjan: no different sounds freqz
09:39 AM rue_mohr: thats not the sample rate
09:39 AM _ami_: whats the problem in using usleep()?
09:39 AM rue_mohr: the same rate is how many adc values there are per second
09:39 AM Gerritjan: no i know the hz thats ot
09:40 AM _ami_: its defined in unistd.h
09:40 AM _ami_: usleep(2000); -> 2ms
09:40 AM rue_mohr: so is it a 22.1khz recording?
09:40 AM rue_mohr: 44.2Khz?
09:40 AM rue_mohr: 8Khz?
09:41 AM rue_mohr: the freq of the sound in the recording has nothing to do with the audio sample rate
09:42 AM rue_mohr: in the same way the rate you pass gas stations is not related to how many times you ask 'are we there yet?'
09:42 AM Gerritjan: this is the code https://pastebin.com/3ZUdM1VQ
09:42 AM Gerritjan: 44.2khz
09:44 AM thardin: looks like a pi
09:45 AM rue_mohr: something dosn't line up in a major way here
09:46 AM thardin: it's measuring how many tmies you can set some register in the SoC per 2 ms?
09:46 AM Gerritjan: this is only a test main.cpp im trying to figure out how the interrupts work and how i can get the information
09:47 AM rue_mohr: it looks like a device thats usually used for sound output, is being used for -some kinda- freq input, but with no analog handling
09:47 AM thardin: what are you trying to do?
09:49 AM Gerritjan: https://benselectronics.nl/geluid-detectie-module-/ and get the freq from it
09:49 AM thardin: if you want to measure the frequency on a signal on a GPIO pin then you should set up an ISR that triggers on a rising or falling edge, and use a timer to measure the time between two calls
09:49 AM Gerritjan: and it is digital
09:49 AM thardin: laziers version is to just spinlock in the main thread, waiting for the pin to switch between states
09:49 AM Gerritjan: so ISR with interrupt?
09:49 AM thardin: which would be a bit coarser
09:49 AM rue_mohr: so, the sound you have comming in is already at logic levels?
09:50 AM rue_mohr: yea, multitasking will makea mess of anything like this
09:50 AM Gerritjan: yes\
09:50 AM Gerritjan: it logic
09:51 AM thardin: did you look at the signal with a scope to verify this?
09:51 AM rue_mohr: aaand this is reading anything, its just continiously setting the output high
09:52 AM Gerritjan: yes it does but im just testing how it works before i can make something
09:52 AM Gerritjan: and i want to do it right
09:53 AM rue_mohr: if now() does return ms
09:53 AM Gerritjan: yes
09:53 AM rue_mohr: for(stop = now() + 2; now() < stop; ) { }
09:54 AM rue_mohr: a gpio pin will usually stay high until its set low
09:54 AM rue_mohr: an input pin will usually ignore output commands unless your turning the pullup on and off
09:54 AM Gerritjan: its reseted with the eds
09:55 AM rue_mohr: hmm
09:58 AM rue_mohr: but yea, a multitasking system cant do anything on time
09:58 AM rue_mohr: sometimes before (if its not too soon)
09:58 AM rue_mohr: otherwise you want someting running a single process loop like an 8 bit avr :)
09:58 AM rue_mohr: dedicated to the task
10:47 AM PsySc0rpi0n is now known as HelloShitty
02:35 PM JanC is now known as Guest46476
02:35 PM JanC_ is now known as JanC
10:56 PM enh: HI
10:56 PM enh: I got a question.
10:57 PM enh: If I have two atmega328p communicating over SPI
10:57 PM enh: If the master lows the slave SS
10:58 PM enh: but the slave keeps its own SS high
10:58 PM enh: how does the SS line stays?
10:58 PM enh: Can I use this as a sign that the slave is not ready to answer the SPI call?
11:04 PM enh: ...
11:04 PM enh: Emil? cehteh? Lambda_Aurigae? _ami_?
11:04 PM enh: Casper?
11:05 PM enh: dsalychev1?
11:05 PM enh: NoHitWonder?
11:06 PM enh: Everybody is sleeping... Oh my...
11:10 PM Casper: if it follow the specs, the SS line will not be set high, but high impedance, and the pullup will be what bring it up
11:10 PM Casper: so any low = low
11:15 PM enh: If I set the master GPIO connected to slave SS to input, will I be able to read the pullup HIGH?
11:16 PM Casper: if both are set to input, yes<
11:26 PM enh: Thanks, Casper