| Electronics > Beginners |
| Atmega8 PD and PC ports |
| << < (3/3) |
| Nusa:
--- Quote from: Lux_ on February 18, 2019, 06:39:31 pm ---Its just the same but without the rest of my code which it shouldn't interfere with it. In the main code i even comment out the functions and still it wont work. --- End quote --- 300 baud serial? For real? It's not the same unless you also comment out the enabling of that horribly behaved interrupt handler, although that isn't your immediate problem: DDRD = 0; // all PD pins configured as input All those led output pins are configured as inputs. |
| Lux_:
--- Quote ---300 baud serial? For real? --- End quote --- Yes 300 baud, I sent the serial data trough a optocoupler normal 9600 baud doesn't work its to fast. --- Quote ---It's not the same unless you also comment out the enabling of that horribly behaved interrupt handler, although that isn't your immediate problem: --- End quote --- Sorry It missed that part. But thanks for your feedback on the interupt piece. I have found this piece of code on the internet it said it was a bad practice to do it this way but I don't know what is bad and how to fix it, can you explain? (It works but I want to learn how to do it better.) --- Quote ---DDRD = 0; // all PD pins configured as input All those led output pins are configured as inputs. --- End quote --- :palm: this what you get when you're copying code form the internet :) But thanks for pointing it out, I just started working with using ports directly. |
| Nusa:
As a rule, interrupt handlers should only do trivial processing if at all possible. And they should exit as soon as possible. For what you're trying to do, I'd suggest that the entire body of the handler should be something like: sendReport = true; add a global initialized to false: bool sendReport = false; Move all your reporting code to its own function: void printReport() { // all that serial data } Then somewhere in your main loop, add: if (sendReport) { printReport(); // send the report sendReport = false; // reset flag set in interrupt } Note that by waiting until the main loop gets to that particular test, you ensure your data is in a valid state for reporting before doing so, and not somewhere in the middle of sensor sampling. |
| Lux_:
--- Quote from: Nusa on February 19, 2019, 08:57:22 pm ---As a rule, interrupt handlers should only do trivial processing if at all possible. And they should exit as soon as possible. For what you're trying to do, I'd suggest that the entire body of the handler should be something like: sendReport = true; add a global initialized to false: bool sendReport = false; Move all your reporting code to its own function: void printReport() { // all that serial data } Then somewhere in your main loop, add: if (sendReport) { printReport(); // send the report sendReport = false; // reset flag set in interrupt } Note that by waiting until the main loop gets to that particular test, you ensure your data is in a valid state for reporting before doing so, and not somewhere in the middle of sensor sampling. --- End quote --- Thanks for your time and feedback. While reading your post it help solved another problem which i was having. Most of the time one sensor had "corrupt" data and each time it was another sensor. You're comment help solved this problem, the interrupt interrupted the calculation of the sensor data so that is why i received wrong sensor data. I am glad that people on this forum are so helpful towards beginners. So here is my next question: I finished my schematic and started my PCB layout, but now i am stuck with choosing the right footprint. I am using Kicad 5.0 and i chose for everything a footprint expect my inductor. For my stepup converter i am using a SX1308 with a 10uh inductor. I buy all my components on Aliexpress so I started searching for 10uh inductors I found this: But i don't know which footprint it has and which one I need to choose in Kicad. This is the list of inductor footprints that are available in Kicad: https://github.com/kicad/Inductors_SMD.pretty Thanks in advance. Greetings Lux_ |
| Nusa:
Go look at some other listings for that part until you find one that's nice enough to include a dimension chart for the part. Then either pick a footprint that seems close enough (solder pads being a bit too big is better than too small -- the most important dimension is adequate separation between the pads) or create a new footprint of your own. |
| Navigation |
| Message Index |
| Previous page |