newbie ATTiny assembly setting MCUCR

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am hoping someone has done this before and can give me the code necessary.
I need to turn off all other clocks except the ADC clock while the ADC is running then turn all of the clocks back on after the ADC read command is done so I can work with the data collected.

I have read that the basic way is to set SM to 01 in the MCUCR register but don't know how to change these bits for a ADC read only clock or reset them to re enable the MCU and other clocks.

BADBAUD

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

What language? If it happened to be C and avr-gcc in particular it provides:

http://www.nongnu.org/avr-libc/u...

That will manipulate the sleep mode bits for you. When you finally do sleep it will trigger ADSC.

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

AVR assembly, I don't speak C yet.

BADBAUD

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

I speak c but I don't speak assambly...lol

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

Hopefully someone out there still uses assembly and can help me out.

BADBAUD

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

I use assembly exclusively since I no speak 'c'.

Is the reason you want to shut off the master clock is sleep mode to conserve power? Just curious.

Which Tiny by the way?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

ATTiny85. I am trying to read the current pulses (via a MAX chip)going into the ADC pin from a noisy DC to AC inverter. First I turn the inverter on with no load on it and take a reading, everything works fine. Then I connect the load to the inverter and all heck breaks loose. The MCU locks up. I was reading that I could put the MCU in sleep mode and keep only the ADC clock running during the read and was hoping this would prevent the noise from causing the MCU to go bonkers. The idea is to turn off all clocks except the ADC clock during the loaded inverter read then, somehow, wake everything back up. That or put a cap across the ADC input to attempt to block the noise but I think the problem relates more to board layout. A last ditch attempt before I tell the client to re-do their board.

BADBAUD

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

Quote:

Is the reason you want to shut off the master clock is sleep mode to conserve power? Just curious.

I'm just trying to think of some other scenario in which you'd bother to go to all the trouble of sleeping the CPU if it were NOT to conserve power?

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

Yeah Cliff that was my bad. LOOONG day, but it appears that the OP indeed has another reason to want to sleep the MCU.

TO the OP,
Is the avr powered from the device under test?, is the avr properly decoupled/filtered? What kind of load is being used?

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

I didn't lay this board out and can see at least 7 reasons why it shouldn't work at all with a MCU.

The MOSFET driving the load is connected to the same bottom ground plane as the MCU and is way across the board from the DC input. The MCU has no decoupling cap near it. The inverter has no decoupling or filtering on it's DC input. The push button switch has no decoupling and is hanging off the board with 3" of bare wire. The inverter DC input is not diode coupled and is tied to the same +V input as the regulator.

I have repaired all of this to the best of my ability and I disconnected the inverter and connected a signal generator to the ADC input and the code worked just fine. With the changes I made I can connect the inverter and get the code to work about 80% of the time.

Considering the client used a art/drafting major to layout their board it's a wonder the damn thing works at all. I offered to do a new board, correctly, but they had already built and stuffed 400 boards. So after the fact I am trying to get this board to work with the new code they insist is included.

The basic unit had a pushbutton that turned a MOSFET on and off to make different flashing patterns. They now want no load detect and short circuit detect and have quadrupled the size of the inverter they were originally using.

My last hope is that putting the MCU in sleep mode during the ADC read will allow the unit to operate at 100%. I have been promised that I can layout the next revision of the board.

I read somewhere that there is a sleep mode where just the ADC clock runs during a ADC read, if that is true how do I take everything out of sleep to manipulate the data collected by the ADC read?

Can the ADC input (the inverter will still be running after the brief ADC read) be used as a interrupt, a interrupt that is not enabled until after the ADC read? Doesn't make sense to me that this could happen. How does the code run if the MCU is sleeping?

[some paragraph breaks added]

BADBAUD

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

badbaud can I make a suggestion? Can you please break the paragraphs with a space so that the whole message becomes a bit more readable?

My eyes go funny trying to read the message. No offence I hope. :)

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Yes, I have been accused of "babble type" before.
At my advanced age I need to get it down before I forget what I was going to.... hmmm... I had a point here but forgot.

BADBAUD