dc motors

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

hi,i need help in this:

void main() {

unsigned int x;
unsigned int y;
pinb.b2=x ;
pinb.B3=y ;
float adjpot;
float pospot;

//ANSEL = 0x04; // Configure AN2 pin as analog
TRISb = 0xFF; // PORTb is input
// ANSELH = 0; // Configure other AN pins as digital I/O

TRISB = 0; // PORTB is output

do {
pinb.b2 = ADC_Read(0); // Get 10-bit results of AD conversion
adjpot=5.0*x/1023;
pinb.b3 = ADC_Read(1); // Get 10-bit results of AD conversion
pospot =5.0*y/1023;

if(pospot>adjpot)
{
portb.f0=1;
portb.f1=0;
portb.f4=1;
portb.f5=0;
}
if(pospot<adjpot)
{
portb.f0=0;
portb.f1=1;
portb.f4=0;
portb.f5;
}
if(pospot==adjpot)
{
portb=0;

}

} while(1);

}
}

ihope you find me bascom error221

Last Edited: Fri. May 10, 2019 - 02:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, iforget to to say iam using atmega16

ihope you find me bascom error221

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

Then the moderator needs to move this post.

 

Ahd the original poster needs to tell us what kind of help is needed. What does it do that it should not? What does it not do that it should? Please do not tell us that "it just does not work"!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
void main() {

    unsigned int x;
    unsigned int y;
    pinb.b2=x ;
    pinb.B3=y ;
    float adjpot;
    float pospot;

    //ANSEL = 0x04; // Configure AN2 pin as analog
    TRISb = 0xFF; // PORTb is input
    // ANSELH = 0; // Configure other AN pins as digital I/O

    TRISB = 0; // PORTB is output

    do {
        pinb.b2 = ADC_Read(0); // Get 10-bit results of AD conversion
        adjpot=5.0*x/1023;
        pinb.b3 = ADC_Read(1); // Get 10-bit results of AD conversion
        pospot =5.0*y/1023;

        if(pospot>adjpot)
        {
            portb.f0=1;
            portb.f1=0;
            portb.f4=1;
            portb.f5=0;
        }
        if(pospot<adjpot)
        {
            portb.f0=0;
            portb.f1=1;
            portb.f4=0;
            portb.f5;
        }
        if(pospot==adjpot)
        {
            portb=0;

        }

    } while(1);

    } // !!!!!! There is one too many } here ???
}

To try and follow the structure of that code I tried adding back the indentation that must have been lost during the copy/paste but it's not possible to get the code laid out correctly. There seems to be one more } than that are {. So how could this code ever have compiled without error??

 

A lot of this code does not make any sense anyway. For example:

    unsigned int x;
    unsigned int y;
    pinb.b2=x ;
    pinb.B3=y ;

Why are you writing 16 bit ints to what I take it are single bit fields. Also why to the PINB (input register) the atmega16 does not have "toggle" by writes to PIN. Also the values wrintten (x, y) are stack frame autos. They will have no guaranteed value after creation - so you are writing junk anyway.

 

And that's just the first 4 lines of main()! 

 

Suggest you take a step back. DESIGN the solution first, then implement it from the design. Don't just throw random code at your C editor and expect anything sensible to come out of that exercise!

 

Oh and:

    TRISb = 0xFF; // PORTb is input

I don't know a whole lot about 8051 micros (or PICs) but isn't that a register from 8051/PIC or something - it's not an AVR register.

 

Oh and:

        pinb.b2 = ADC_Read(0); // Get 10-bit results of AD conversion

clearly nonsense again. Surely ".b2" is a 1 bit field?? How can you assign a 10 (16) bit return from that function to a one bit field? Oh and then you do:

       adjpot=5.0*x/1023;

But "x" at this stage still contains junk. Was the ADC_read() supposed to be into "x" perhaps.

 

This is just so much nonsense!

 

EDIT: a quick Google tells me "TRISB" is a PIC not an AVR register. How could this code ever be compiled for ATmega16? The compiler will not know "TRISB" (or TRISb)

Last Edited: Fri. May 10, 2019 - 03:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I went back and read OPs other posts and I highly suspect some kind of trolling at work here. I'd warn people not to waste too much time on this as I don't believe there's any validity to any of this.

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

Hi. if i modify like this:

 float adjpot;
 float pospot;

void main() {

  //ANSEL  = 0x04;              // Configure AN2 pin as analog
 ddrA  = 0x00;              // PORTA is input
 // ANSELH = 0;                 // Configure other AN pins as digital I/O

  ddrB  = 0xff;                 // PORTB is output

  do {
  ADC_Read(0);   // Get 10-bit results of AD conversion
  x=  adjpot=5.0*x/1023;
 ADC_Read(1);   // Get 10-bit results of AD conversion
  y=  pospot =5.0*y/1023;

  if(pospot>adjpot)
  {
  portb.b0=1;
  portb.b1=0;

  }
  if(pospot<adjpot)
  {
  portb.b0=0;
  portb.b1=1;

  }
   if(pospot==adjpot)
  {
  portb=0;

  }

  } while(1);

}

ihope you find me bascom error221

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

Still rubbish. In which AVR C compiler is the direction register for port A "ddrA" rather than "DDRA"?

 

C does not work on an " OK, well I guess it's close enough" basis!

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

huida@love wrote:
x=  adjpot=5.0*x/1023;

 

I still have not figured out what this statement does.

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Hi. if i modify like this because iam stuck how I can use the comparator in atmega16 to drive the dc motor

 float adjpot;
 float pospot;

void main() {

  //ANSEL  = 0x04;              // Configure AN2 pin as analog
DDRA  = 0x00;              // PORTA is input
 // ANSELH = 0;                 // Configure other AN pins as digital I/O

  DDRB  = 0xff;                 // PORTB is output

  do {
  ADC_Read(0);   // Get 10-bit results of AD conversion
  x=  adjpot=5.0*x/1023;
 ADC_Read(1);   // Get 10-bit results of AD conversion
  y=  pospot =5.0*y/1023;

  if(pospot>adjpot)
  {
  portb.b0=1;
  portb.b1=0;

  }
  if(pospot<adjpot)
  {
  portb.b0=0;
  portb.b1=1;

  }
   if(pospot==adjpot)
  {
  portb=0;

  }

  } while(1);

}

ihope you find me bascom error221

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

Um. Ok. First, when you post code, click the button that looks like <> and paste your code in the box that pops up. This way it can be read.

 

Second. Read the datasheet for your part. You need to learn how to read and write pins. Look at clawson's avatar: When you get an led blinker like that working, you might know enough to try something more complex.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

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

What is portb.b0 ?

 

Exactly which AVR C compiler is this? Does it really define the registers with struct/bitfields ?

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

huida@love

 

You are going to have to engage with us if you want any real help.

 

That means that if someone asks you a question you are going to have to answer them rather than just continuing to post your own questions.

 

So, as well as the questions that other people have asked above I have some additional ones.

 

The code below is not complete. You need to provide us with COMPLETE code that compiles without errors. And please use the CODE tags in the bar above to do it. Like this...

 

float adjpot;
float pospot;

void main() {

    //ANSEL  = 0x04;              // Configure AN2 pin as analog
    DDRA  = 0x00;              // PORTA is input
    // ANSELH = 0;                 // Configure other AN pins as digital I/O
    DDRB  = 0xff;                 // PORTB is output

    do {
        ADC_Read(0);   // Get 10-bit results of AD conversion
        x=  adjpot=5.0*x/1023;
        ADC_Read(1);   // Get 10-bit results of AD conversion
        y=  pospot =5.0*y/1023;

        if(pospot>adjpot)
        {
            portb.b0=1;
            portb.b1=0;

        }

        if(pospot<adjpot)
        {
            portb.b0=0;
            portb.b1=1;
        }

        if(pospot==adjpot)
        {
            portb=0;
        }

    } while(1);
}

 

Quote:

Hi. if i modify like this because iam stuck how I can use the comparator in atmega16 to drive the dc motor

 

Q1) Why do you now need to use the internal comparator?

 

Q2) How is you hardware configured?

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

Hi, can i use this in atmega16 interrupt [ANA_COMP] void ana_comp_isr(void)
{
PORTB.2=!PORTB.2;

ihope you find me bascom error221

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

huida@love wrote:

Hi, can i use this in atmega16 interrupt [ANA_COMP] void ana_comp_isr(void)...

 

You are ignoring the questions you have been asked. Good luck with your project. I'm out.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

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

HUIDA.

 

You continue to ignore the questions from those people who are trying to help you.

 

Very soon a moderator will lose patience and lock this thread. You are just wasting everyone's time.

 

Moderator

 

Ross McKenzie ValuSoft Melbourne Australia

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

 

 

 

 

 

 

 

 

 

 

 

HI,first of all iam very sorry iam not ignore  any of you but not know what to do for  that code again iam sorry please pardon me

 

 

 

 

 

 

 

 

 

 

ihope you find me bascom error221

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

HI, Brian Fairchild  Iam sorry for all that what i need to say in my project  iuse dc motor to supplly  wire and feed back pot sensor thri wire also drive this by use another pot make the motor move 180 degree and agin back to zero ,the main controller atmega16 ihope you got me and accept my apolgy thank you

ihope you find me bascom error221

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

You still haven't said which C compiler. Post #13 possibly suggests Codevision?

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

Try this:

 

#include math.h

float adjpot;
float pospot;

void main() {

	//ANSEL  = 0x04;              // Configure AN2 pin as analog
	DDRA  = 0x00;              // PORTA is input
	// ANSELH = 0;                 // Configure other AN pins as digital I/O
	DDRB  = 0xff;                 // PORTB is output

	do {
		x=  ADC_Read(0);   // Get 10-bit results of AD conversion
		adjpot=5.0*x/1023.;
		y=  ADC_Read(1);   // Get 10-bit results of AD conversion
		pospot =5.0*y/1023.;

		if(pospot>adjpot)
		{
			portb.b0=1;
			portb.b1=0;

		}

		if(pospot<adjpot)
		{
			portb.b0=0;
			portb.b1=1;
		}

		if(fabs(pospot-adjpot) < 0.1)
		{
 			portb=0;
		}

	} while(1);
}

Jim

 

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

Last Edited: Tue. May 14, 2019 - 07:14 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,clawson,Iam sory first of all the code which I use yes itis codevision

ihope you find me bascom error221

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
 //ANSEL = 0x04; // Configure AN2 pin as analog
TRISb = 0xFF; // PORTb is input
// ANSELH = 0; // Configure other AN pins as digital I/O

TRISB = 0; // PORTB is output

 

TRISB??  This is not a PIC site.

 

huida@love wrote:
Iam sorry for all that what i need to say in my project  iuse dc motor to supplly  wire and feed back pot sensor thri wire also drive this by use another pot make the motor move 180 degree and agin back to zero ,

 

You do not want to use a standard DC motor for this.  A STEPPER motor is a far better choice.

 

Does your professor require you to use a DC motor?

 

Jim

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

jgmdesign wrote:
Does your professor require you to use a DC motor?

My guess it this is a line following robot exercise!

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Hi,I just need make a DCmotor move to angle of 180 and back to 0 with two pot as sensors by using internal cmp in atmega16

ihope you find me bascom error221

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

huida@love wrote:
Hi,I just need make a DCmotor move to angle of 180 and back to 0 with two pot as sensors by using internal cmp in atmega16

 

I guess your professor did not explain, or you were not there for class that moving a DC motor from 0 to 180 degrees is not so simple.  A conventional DC motor goes from 0RPM (static) to full speed.  There is no 'stepping' in between.  Sure theres ramping, but for a small DC hobby motor that shaft is so small the ramp is useless.  Then theres the issue of how to stop the motor from moving past the 180 mark.  You can short the power terminals together, but there is going to be overshoot. 

 

This applies to going from 180 back to zero position.

 

TO put it kindly....your project is missing some key elements.

 

JIm

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

Do you even have a blinking LED working...you must try that first!

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!