pwm always gives VCC on the output !!!?

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

Hello everybody
pleeease help me..

I'm using this function to control the speed of a small DC motor using pwm, and the problem is that the output of OC1A is still VCC whether I give OCR1A any value including 0xFFFF and 0x0000 and any value between them.. this is the function...

/*********************************************
Chip type           : ATmega8535
Program type        : Application
Clock frequency     : 4.000000 MHz
Memory model        : Small
External SRAM size  : 0
Data Stack size     : 128
*********************************************/

#include 


//MOTOR:
//**********************************************************
//Motor Pins:
//--------------
//PIND.5=OC1A:PWM source for the motor .
//
//The following function is used to set Timer1 in fast pwm mode
void settings(void)
{
DDRD |=0b00100000;//PORTD.5=OC1A is output//
/*
// Bit7:6=COM1A1:0(Compare Output Mode for Channel A)=10>>(Clear OC1A/OC1B on Compare Match, 
// set OC1A/OC1B at TOP (Non-Inverting)) with   WGM13:0=1111
// Bit5:4=COM1B1:0(Compare Output Mode for Channel B)=00>>Normal port operation, OC1B disconnected.
// Bit3=FOC1A(Force Output Compare for Channel A)=0>>No Forcing for Output Compare of Channel A 
// Bit2=FOC1B(Force Output Compare for Channel B)=0>>No Forcing for Output Compare of Channel B
// Bit1:0=WGM11:0(Waveform Generation Mode)=11+WGM13:2=11>>Mode: Fast PWM top=OCR1A
*/
TCCR1A=0b10000011;

TCNT1=0xFFFE;// MAX count value;
/*
// Bit7=ICNC1(Input Capture Noise Canceler)=1>>Input Capture Noise Canceler On
// Bit6=ICES1(Input Capture Edge Select)=0>>Falling Edge
// Bit5=Reserved Bit=0;
// Bit4:3=WGM13:2(Waveform Generation Mode)=11+WGM11:0=11>>Mode: Fast PWM top=OCR1A
// Bit2:0=CS12:0(Clock Select)=001>>>clock source clkI/O/1 (No prescaling).
*/
TCCR1B=0b10011001;

OCR1A=0x9999;//PWM Duty
}

:( :(

thanks in advance

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

In general, Mode 15 isn't of much use to drive OC1A. Either use OC1B, or Mode 14.

[and as your testing showed, I don't know if it even works or does anything useful.]

Lee

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

Hi Lee

I've read this statement in the data sheet :

Quote:

When using OCR1A as TOP value in a PWM mode, the OCR1A Register can not be
used for generating a PWM output.

with this statement I couldn't understand the purpose of mode15 ???

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

to drive OC1B

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

you mean when I want to drive OC1A I use OCR1B
and when I want to drive OC1B I use OCR1A???

And if I'm using both OC1A and OC1B , which register should I use???

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

No, OC1A can not be used for a PWM output in mode 15, it can only be used for TOP. OCR1B affects OC1B.

If you want to use both OC1A and OC1B, you need to use a mode that uses ICR1 as TOP.

Regards,
Steve A.

The Board helps those that help themselves.

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

The problem is that I'm using ICR1 to count the rpm for the motor .

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

Quote:

you mean when I want to drive OC1A I use OCR1B
and when I want to drive OC1B I use OCR1A???

No, in mode 15 OCR1A holds the TOP value and OC1B hold the duty cycle value. There is only one PWM output in this mode, on OC1B.

Quote:

And if I'm using both OC1A and OC1B , which register should I use???

If you want two PWM outputs thne you cannot use mode 15. Mode 14 is usable. TOP value (for both PWMs) is in ICR1. Duty cycle values are in OCR1A and OCR1B.

The rationale for mode 15 is clearly spelled out in my copy of the data sheet. Read all of the section on Fast PWM Mode (it's a staggering 2 pages...) and look for a paragraph starting "The procedure for updating ICR1 differs from updating OCR1A [...]", and pay special attention to the double-buffering capability of OCR1A and the implications of this. Then ask yourself if you need to change the TOP value, and if you're willing to do the extra coding to ensure that the counter does not "run away" to 0xFFFF. If you need both PWMs you will be forced to this (again, if you at all need to manipulate the TOP value). If you only need one PWM, and you need to change the TOP value then you can get away with a simpler piece of code for updating TOP by using mode 15.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

ia17348 wrote:
The problem is that I'm using ICR1 to count the rpm for the motor .

Then you are going to have to give something up, or move to another AVR.

Regards,
Steve A.

The Board helps those that help themselves.

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

Quote:

Then you are going to have to give something up

I'll try to use timer0 and timer2 , but this will change the schematic of the circuit of my project...

Quote:

or move to another AVR

Do you mean that other AVRs have different properties of counters???

any way human learns just from his mistakes... :P :P

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

Quote:

Do you mean that other AVRs have different properties of counters?

Yes, he does.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

Another question..:oops:

I remember that one time I read that Timer1 still works alone , and it just needs to define the settings for one time , do other timers( 0 and 2) need additional things like resetting the values in interrupts every time or it works just by defining the settings one time....?

thank you guys for replying :) :)

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

Quote:
The problem is that I'm using ICR1 to count the rpm for the motor .

Now you are way losing me.

Do you mean you are storing some kind of RPM count in the ICR1 I/O register pair? If so, then simply store your RPM information elsewhere.

Do you mean that you are using timer1 in ICP mode via the ICP pin to time between pulses of some kind? If so, then how are you going to do PWM at the same time? If not, what do you mean by that?

I'd have to dig through the datasheet to see if this can be done simultaneously. Never thought about doing that before. Perhaps with one of the fixed-TOP modes like 5,6,7 ICP can run at the same time.

So, do you want one PWM output or two? Is 8-bit resolution enough, or not? Is 9- or 10-bit enough?

Are you timing between pulses to get RPM indication? What pin is your RPM pulse information coming in on?

Based on those answers, I/we can come up with scenarios to avoid making a board rev. However, I wouldn't see any problems in changing the >>schematic<< of the circuit. What could be the drawback there? Surely you are going to lash it up somehow before a board spin? And if not, don't you want to do it in a fashion that has a chance of working?

Lee

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

You're right Lee

Quote:

Do you mean that you are using timer1 in ICP mode via the ICP pin to time between pulses of some kind? If so, then how are you going to do PWM at the same time? If not, what do you mean by that?

I'm using ICP to calculate the period between pulses from a proximity sensor...

I'm going to use Timer0 and Timer2 instead , and I'll test it with my test board...

thanks for replying

Last Edited: Fri. May 23, 2008 - 11:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Helloooooooooooooooooooo...

It worked with Timer0 and Timer2 (I've tested it using a test board).....

Thank you very very much for help :P :P :P

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

Depends on what you mean by "resetting the values". All timers wrap at 0xFF (8-bit timers) or 0xFFFF (16 bit). Do you want to reset the timer at a lower value, eg at TOP? Are you talking about CTC modes?

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

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

I meant that Do we need to regive the values of timer's registers , for example value of OCR0, in an ISR like Timer0 Overflow or output compare match...

any way after I tested it , the answer is : NO, they don't need to update their registers' values every time...

sorry for wasting your time with my stupid question, and thank you very much for giving attention. :oops: :oops:

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

JohanEkdahl wrote:

No, in mode 15 OCR1A holds the TOP value and OC1B hold the duty cycle value. There is only one PWM output in this mode, on OC1B.

If you want two PWM outputs thne you cannot use mode 15. Mode 14 is usable. TOP value (for both PWMs) is in ICR1. Duty cycle values are in OCR1A and OCR1B.

I found this thread and it ended a frustrating effort to fully understand PWM on the AVR :D

I had come to the point where I understood basically everything being explained in the datasheet. I also had several different versions of PWM working on my AVR. I also understood the benefit of double buffering when using OCR1A as TOP. I couldn't, for the life of me, come up with how I could do PWM when using OCR1A as TOP.

After reading the datasheet about 60 times, searching Freaks, and reading too many web pages to count, I finally found this thread. Thank you. As soon as I read;

Quote:
There is only one PWM output in this mode, on OC1B.

the lights came on and all was clear.

Thank you for stating what should have been obvious to me in the first place. On the plus side, I sure learned a lot.

Brett

The game of life is not so much in holding a good hand as playing a poor hand well.
H. T. Leslie

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

Knowledge comes in bursts. IIRC, I was able to write that answer in that definitive manner because we've had a similar thread just a few days earlier. Glad that it came to use!

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]