PWM using Butterfly Board

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

Hi,

I'm currently trying to control a small motor using PWM.
The problem I'm having is getting my signal out. Here's what I'm working with:

DDRB = 0xFF;
TCCR0A = (0<<FOC0A) | (0<<WGM01) | (1<<WGM00) | (1<<CS02) | (1<<CS00); // Set PWM Phase Correct Mode with CLK/1024 prescaler
OCR0A = 50; // just chose a random value

How do I get this wave out to PORTB?

Thanks,
Jason

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

Wrong forum. Should be the regular AVR forum, not the XMega forum. Hopefully, a moderator will move it.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Quote:

How do I get this wave out to PORTB?

Without telling us which AVR it is then folks can only guess. There will be a fixed pin assigned to be the OCR0 output for timer 0 on your particular AVR - that is where the output of the waverform generator will appear. It may be on PORTB, then again, it may not be.

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

All apologies, folks. I didn't mean to post in the wrong forum. I'm still very new to this.

I'm using the AVR Butterfly board which uses the Atmega169 uC.

I was going to assign something to a port. Example
PORTB = OC0A;

I just don't know exactly where my PWM is or the proper way to to go about this.

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

Well apologies to you. The mention of "butterfly" in the title should have told me it was a mega169. But if you look at page3 34-35 of the Butterfly user guide where the schematics are you can first see that timer 0's PWM output (OC0A) is on pin PB4 but you can further track this to see that it's connected to the center pin of the joystick. As this is usually open circuit you should be able to gain access to the signal without it being interfered with as long as you don't touch the joystick.

Note that Joe Pardue (smileymicros) has a PDF that shows which of the Butterfly signals are available for general use - search out a copy if you don't already have a copy.

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

Butterfly Alternate Pin Use
http://smileymicros.com/download...

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

Hi Folks,

I've been working diligently, and here's what I have now. I have a small DC motor connected to a 9V source, and isolated from the Butterfly.

I've written a code to divide the clock frequency of 2 MHz by 64. I think I've set the registers and OCR1A so that OC1A switches at 125 giving me about half of my 9V??

Everything compiles, but when I turn on the board, The motor makes 1 revolution and stops. Here's my code. Anyone have any advice? Thanks for your time.

#include

int main (void)
{
DDRB = 0xFF;
TCCR1A = (1<<COM1A1)|(1<<COM1A0) | (1<<WGM10) |(1<<WGM11) ; // Set PWM Phase Correct Mode with CLK/64 prescaler
TCCR1B = (1<<WGM13) |(1<<CS11) |(1<<CS10);
OCR1A = 125; // If it counts to 256, this is about half

for(;;) {}

return 0;
}

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

I have example projects for the Butterfly to control PWM and motor speed. You can download 'C Projects Source Code Next Gen' from my website Downloads menu.

Also look at:
https://www.avrfreaks.net/index.p...
and
https://www.avrfreaks.net/index.p...
and
http://www.societyofrobots.com/m...

Smiley

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

I really appreciate all the feedback guys. I've gone from basic C programming on a computer to embedded programming, and the learning curve is steep. And Smiley, I'm very grateful for and impressed by how much support you provide for the Butterfly. I've pencil marked and dog eared your book to death.

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

jbelk7 wrote:
I really appreciate all the feedback guys. I've gone from basic C programming on a computer to embedded programming, and the learning curve is steep. And Smiley, I'm very grateful for and impressed by how much support you provide for the Butterfly. I've pencil marked and dog eared your book to death.

Second that, even though I am sure Joe has heard this 1000 times. I might have to buy a 2nd book as this one is falling to pieces from all the highlighting and folding of pages :P I started as a member looking for instant solutions but through this forum and Joe's book I have been pushed to LEARN these concepts and I am having so much fun!

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

It is always great to hear things like this. Sometimes I feel like I'm howling in the wilderness.

Thanks,
Smiley

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

Quote:
Sometimes I feel like I'm howling in the wilderness

What you do in your spare time with the local nymphs there in backwoods Tennessee is none of our business. We're just glad you're so good at sharing your wisdom and experience and are willing to do so.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org