ADC is not working!

Go To Last Post
136 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

Too often you have made posts where it seems your reluctance to read wastes others time answering questions you would already know the answer to if you had read entire documents/articles you were directed to previously.

 

About 20-25% of the job of being a programmer is reading. You cannot avoid it if you want to program things. If you can't be bothered to read then forget the notion of becoming a programmer.

Yes, you are right.

 

Last night and the evening time I spent debugging my code to run multiple sensors, and later night before sleep I was reading about periodic polling, it seems an important topic in programming. But one of my problems is that I don't find the exact good resource to read about; for example last night when I was searching about how to look for polling a pin while working with multiple tasks. So first I type that in Google, then I get various results, and still not getting the exact explanation about what I'm looking for. So it's me who is wasting the time I waste my time and as a result others time, but I don't mean it.

 

for example here's one of the article I was reading last night:

I typed "polling vs multithreading" in Google I got various results, most are general and not specific. So getting information about real applications isn't so obvious to me, because maybe I don't know where is the best to look.

 

I ran into this article, but it's not relevant specifically, it's professional programmer's opinion, so I'm not getting a solution for my project:

https://thetechsolo.wordpress.com/2016/02/29/scalable-io-events-vs-multithreading-based/

 

And others are alike, not very specific.

 

This is how when I'm looking for something, and that's how I get back to the forum and ask about my issue.

 

 

Kartman wrote:
I know a programmer who is dyslexic. He has trouble reading but he makes an effort to read things carefully and his uptake is swift. Wolfy, too often you skip over things you think are irrelevant but are actually fundamental. Then at some later stage they become important. I’d suggest you take a good look at how you learn and acquire information. To the outsider it appears random and not very effective.

Yes of course, programming is huge, I know I'm only working with C. It's one language and I get a lot of issues.

 

You are right mostly, especially when I read datasheets, I skip the explanations and go to the registers section :) To get the necessary bits for my settings, and it works but not perfectly. I think I save time looking into the details.

 

Just look to the registers, how to set the peripheral, do it in the code, compile, get the results, not working! Check again, change something, not working! Ask in the forum.

 

If it's not a peripheral, like; testing and implementing a new strategy; like the co-operative multitasking, it took me the weekend to get it to work, did some modifications last evening, and ran 5 tasks.

 

My today's goal is to run, LCD, DH11, just for this setup, I needed to learn how to setup delays and pin polling functions.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

clawson wrote:

Too often you have made posts where it seems your reluctance to read wastes others time answering questions you would already know the answer to if you had read entire documents/articles you were directed to previously.

Indeed -- and right above...see #74 #75 #76 and others.

 

After 100+ posts, this thread still cannot figure out why that darned ADC on OP's AVR doesn't operate properly?  But apparently just OP's AVRs?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

Indeed -- and right above...see #74 #75 #76 and others.

 

After 100+ posts, this thread still cannot figure out why that darned ADC on OP's AVR doesn't operate properly?  But apparently just OP's AVRs?

But it was about the prescalers, the problem was solved. But I didn't close the thread, I continued and moved to other issues while I was thinking it's not very professional looking that the thread us about something and there are other topics involved.

 

But anyway the ADC problem is OK now, it's working OK.

 

I'm thinking to open a new thread which to be a subtopic of Mr Kartman's method in the co-operative multitasking.

 

I actually opened this thread:

https://www.avrfreaks.net/forum/looking-appropriate-sensors-medium-diploma-graduation-projects#comment-2554936

 

It doesn't get new posts, but I'm thinking of changing the title of the thread and continue there, because I think there are viewers who may enter this thread which it has the title of ADC, but also has other issues involved.

Last Edited: Tue. Sep 25, 2018 - 02:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Didn’t i cover this very situation in my tutorial?

 

I mean, if I needed a delay inside the function, or a pin polling.

 

For example, at the end of the DH11 read function, there's 2000ms delay. How to be able to do this delay and running other tasks? I think it's not possible, I tried to think about it, but the tasks have to run sequentially.

 

I thought about something to get out of the function until the delay finish and come back again, that's not possible for my current experience in C. 

 

But another way I thought about is to divide every part of the functions, but like DH11 read function, each part is based on the previous one. So I must do the required delay and continue the function. I think this is what you talked about in your tutorial which is called "thread stack" to take it apart and run the other functions, and at the same time this thread perform its delay and run on its own stack.

 

Also, the part which is polling the pin high for 80us and also 80us low.

 

 

I just did a quick Google search and got these links:

https://en.wikibooks.org/wiki/Embedded_Systems/Threading_and_Synchronization

 

I think I have to apply the principles in this link, do you agree with me?

 

Does your co-operative method acquire the delays feature? I seems to me that it's good for running multiple tasks for 10ms each tasks, so if a task is requiring a delay for 2000ms, how to do it as the task time is only 10ms?

 

 

====================================================================================================================

 

 

Late night update:

Found this link, which recommends using interrupts when applying multitasking and there are pins need accurate polling.

https://www.elesoftrom.com.pl/en/os/multithreaded_programming.pdf

 

So, just reading the first part "on page 4" it says, stop polling and use interrupts.

 

For multitasking with co-operative method, if there's no need for anything that requires delays or polling, then only using the timer0 CTC mode is enough for scaling the 10ms periods for each task.

 

But if there are tasks which requires delays or polling, then it's the time to include a part which takes care of these delays and pollings. It recommends interrupts, I won't say it's the only solution.

 

Another possible solution is to include another timer or use interrupts.

Last Edited: Tue. Sep 25, 2018 - 08:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Around we go in circles yet again.

Clearly, if you need microsecond timing the task-timers aren’t the solution. For your 2000ms delay, then the task-timers are of use. So you want your task to run, load a 2 second time for the task to sleep. When the task wakes up, do something next and so on. So you need a means of remembering what the task is to do next, so you need a static variable to remember this. Then a switch statement based on this variable to decide what the task is to do. This is called a ‘finite state machine’. Very simple and a fundamental concept in both hardware and software. Your challenge is to write a piece of code that turns an led on for a short time,off for a short time,on for a longer time then off for a longer time then repeat. This has four states. Using one task and one task timer implement this using a finite state machine. It should take you no longer than half an hour and is around 16 lines of code. Remember - one static variable and a switch statement.

Last Edited: Tue. Sep 25, 2018 - 10:01 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What I want to do:

 

1. Task1 Run DH11 read code which requires 2s delay init, 18ms delay response, then polling pin 80us HIGH/LOW.

2. Task2 send data to the LCD also need delay for data on the LCD.

2. Read IR signal as task3.

3. Read push button as task4.

 

My question is, as the I'm in task1, and the I'm in the 2s delay, how to run the 2s delay and take car of other things; e.g. task2,3 and 4?

 

Do I need what's called a "thread" to put task1 which needs dela or I can do it with "multitasking"? I'm sorry I don't mean to skip your suggested challenge, as I'm preparing for it but I need more clarification about what I want to do.

 

 

======================================================================================================================================

Now for my basic multitasking, there's TMR0 for the 10ms chunks, OK.

 

Then if I want to add the code which requires delays and pollings, then that requires another timer for that, and runs differently. It runs as a counter for the required periods, and it has to enable interrupts like TMR0.

 

 

So now I have two timers with interrupts.

1. TMR0 for multitasking 10ms chunks.

2. TMR1 for multitasking  delays and pollings.

 

Do you agree with this arrangement?

Last Edited: Wed. Sep 26, 2018 - 07:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
2. Task2 send data to the LCD also need delay for data on the LCD.
Why does that have to be a "task" at all? Humans are slow and stupid. You have 100's of ms between updates to keep them entertained. So just stick that in the while(1) loop in main() so it gets done when nothing else is going on. Put the time critical stuff on timer interrupts so those things happen exactly when they need to occur - stealing the time from the slow LCD update happening in the "background".

 

Can't help you are "over thinking" this - find a need for multi-tasking when it's not really appropriate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Cliff - he's confused enough as it is!

 

My question is, as the I'm in task1, and the I'm in the 2s delay, how to run the 2s delay and take car of other things; e.g. task2,3 and 4?

You don't use a 2 second delay(). That why I have task timers to wake up tasks in the future so you do others thing in the meantime. The challenge I set you illustrates this - that why I set it.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A quick update, maybe not related to the thread but as I'm now reading the Atmega328p datasheet, in TMR2 section, chapter 17.

 

There's one little errata.

 

 

 

It's in Rev. 8161D–AVR–10/09

 

Also, in Atmel-8271I-AVR- ATmega-Datasheet_10/2014, page 153, same errata.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

wolfrose wrote:
It's in Rev. 8161D–AVR–10/09 Also, in Atmel-8271I-AVR- ATmega-Datasheet_10/2014, page 153, same errata.

I see you are now studying the datasheet -- a good start.

 

You do realize there have been many datasheet versions since the D version in 2009 that you referred to?

 

And you do realize that Atmel no longer exits?  And has not for several years?

 

The new overlords have been releasing there own branded versions of the datasheets for the existing models.  What do we find there?

 

 

So given the above, what is the purpose of your post?  What do you expect to happen?  Even if a "powerful" person saw your post, would they go back to the D version from 2009 and make that correction?

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

 

You do realize there have been many datasheet versions since the D version in 2009 that you referred to?

 

I thought Atmel-8271I-AVR- ATmega-Datasheet_10/2014, is the ultimate next one. I didn't search in the web because last time I downloaded a datasheet for this chip, I didn't how I got it but I thought "OK this could be the latest one".

 

 

And you do realize that Atmel no longer exits?  And has not for several years?

Yes it's now in Microchip ownership.

 

 

The new overlords have been releasing there own branded versions of the datasheets for the existing models.  What do we find there?

OK I better look for those ones.

 

So given the above, what is the purpose of your post?

Just a comment, I wanted to know the members' opinion about it.

 

What do you expect to happen?

You know, things in big companies; like, Microchip, I before years was reading a datasheet for a PIC MCU, and found an errata and posted that to the website, but I don't remember if they corrected it or not.

 

I wanted to know the members' experiences with the erratas, should I care about it? Should I post in the forum or post to the companies' website.

 

Even if a "powerful" person saw your post, would they go back to the D version from 2009 and make that correction?

 Absolutely not, but could they delete the old versions from online? Or, yes they keep it as a series of copies for the same chip.

 

 

For example, I just hit a search online for "328p datasheet", the first link is this one from sparkfun:

https://www.sparkfun.com/datasheets/Components/SMD/ATMega328.pdf

 

Rev. 8025I–AVR–02/09 - same one I had.

 

That's why I think it's the latest version, when I got the "Atmel-8271I-AVR- ATmega-Datasheet_10/2014" I thought "OK this is the ultimate one!", and either ones are not!

 

 

The second link from Microchip - 7810D-AVR-01/15, but it also has the same errata:

http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-7810-Automotive-Microcontrollers-ATmega328P_Datasheet.pdf

 

 

It's obvious now why I don't have the latest one!

 

OK OK I got it :) From the chip's page in Microchip website, and it's really nice, it has a lot of document related to the device that's really interesting!

https://www.microchip.com/wwwproducts/en/ATmega328P

Last Edited: Fri. Sep 28, 2018 - 07:59 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wolfrose wrote:
the first link is this one from sparkfun:
When you google "ATmegaXXXX datasheet" then always look down the list for the ".microchip.com" one and take that. That will (hopefully) ensure you see the very latest datasheet as someone like Sparkfun or LadyAda or whoever else might be holding a copy might have an out of date copy.

 

IOW always go to the "horse's mouth".

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

IOW always go to the "horse's mouth".

I love these phrases :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's actually a phrase from horse race betting. When you have a tip that you believe a certain horse is a dead certainty to win you might say "I got a tip from the stable owner" or "I got a tip from the jockey" but if you want to emphasise just how certain the tip really is you could use the phrase "I got a tip straight from the horse's mouth" on the basis that no one knows better than the horse himself whether he thinks he will win!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about this multithreading strategy?