Motor switching control

Go To Last Post
110 posts / 0 new

Pages

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

A way is to simply first read the EEPROM location, compare it to the new value and if they are the same, don't write the value.

I would not go for the voltage monitoring route. Too complicated for the application.

Just store the current motor # and run hours, as suggested before, every hour. Robust enough IMO.

If this is a given task, it sounds to me like a real job. What's your job title?

edit:spelling

Last Edited: Mon. Jul 30, 2012 - 07:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JayJay,
Read the beginning of the thread. The OP wants to use four motors to do the job of one motor because according to him the motor he is going to use can only run for 8 hours. So his idea is to but more motors and run each one 8 hours at a time with all their shafts tied together.

The original spec was three phase, then single phase 230. A REAL job? Goodnes I hope not

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

And once again he has snookered us into helping him do the absolutely worst thing you can do.... select a processor and write a program based on no specs, and start debugging it. This should never be done. You always least need a "user case" of how it works, the inputs and outputs, voltage, current. If its all an imaginary project for intellectual design process testing, we are failing badly. I like problem solving and writing microcontroller programs, and sometimes I jump right in to the programming part and start typing, and I'm thinking of subroutines I'm going to need and I stub those in. Top Down, Bottom Up. Did the name of that process change to something else recently? Rapid Prototyping? But I sure don't start buying parts with my money or someone else's money until I've got sort of an idea what I'm going to do. So give us the Big Picture Justin, and we'll debug the program in a day or two. In the meantime, this looks like a job for an Off The Shelf Programmable Logic Controller (which I've only heard of, never used or programmed). They are the King's of Industrial Controllers.

Imagecraft compiler user

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

I use plc's at times and they are the big boys for sure, but my argument has been why use four motors with their shafts tied together to do the job of one continuous duty motor? The op made it rather clear in the second page of the thread. No matter. I am guessing this thread is dead

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

Quote:
A REAL job? Goodnes I hope not

That's the only thing I want to know.

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

sorry freaks for mis-understanding, this is a real job. the problem is that i cant get an oppertunity to discuss the topic with end client.my connection through a third party.my only duty is to program the microcontroller itself.
anyway i clear some doubts with him today......
*single phase motor
*Not same duty
*client have 4 different motor and want only one work at a time for 8 hours

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

Now it's single phase, 4 motors with different duty ratings, running 8 hours each, on one shaft, AND, we still don't know how the motors are attached to the shaft.

justinjohney wrote:
...my only duty is to program the microcontroller itself.

But you are here asking us how to do that every step of the way. Do you feel that you are qualified enough to write the code and not have it fail and damage the equipment or hurt somebody? This is a very serious question that you have to answer honestly for yourself.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Quote:
Now it's single phase, 4 motors with different duty ratings, running 8 hours each, on one shaft, AND, we still don't know how the motors are attached to the shaft.

no one shaft different shafts

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

justinjohney wrote:
Quote:
Now it's single phase, 4 motors with different duty ratings, running 8 hours each, on one shaft, AND, we still don't know how the motors are attached to the shaft.

no one shaft different shafts

justinjohney wrote:
Quote:
What is the function of the motors?

for water pumping
Quote:

Are they driving the same shaft?

yes.
...

You told me they are driving the same shaft when I asked you before. :?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Deleted. Not important.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Tue. Jul 31, 2012 - 07:21 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

updated':P'

Last Edited: Wed. Aug 1, 2012 - 04:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You were told that this is wrong. Why is it still in you code?

         while(hour==8)    
         { 
            hour=0; 
            change_motor(); 
         } 

Change it to:

         if(hour==8)    
         { 
            hour=0; 
            change_motor(); 
         } 
int main(void) 
{ 

   second=eeprom_read_byte(&saved_second); 
   minute=eeprom_read_byte(&saved_minute); 
   hour=eeprom_read_byte(&saved_hour); 
   n=eeprom_read_byte(&saved_n); 
   init_ports(); 
   start_motor(); 
   init_timer(); 
   init_adc();

// ONLY enable global interrupts here
// not in you init routines.
   sei();
 
   while(1) 
   { 
      read_adc(); 
      if (ADC_check_says_power_dying()) 
      { 
         commit_data_to_EEPROM(); 
      }        
   } 
} 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

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

Did any of your code enter into timer interrupt?
Which one?

If any did it, start with one which existed, please add functionalities one by one, beginning by the more linked to this topic, test them one by one (ADC testing and EEPROM playing are luxury : the main functionality is in this topic title you chose)

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

Quote:
Did any of your code enter into timer interrupt?

void init_timer(void) - is this function able to start the timer. some where i read that avr timer is independently work. so if we assign a clock to it then it will automatically start.(forget if i'm wrong)
Quote:
EEPROM playing are luxury : the main functionality is in this topic title you chose

i need to store the variables before power off. which is essential for this situation.

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

justinjohney wrote:
i need to store the variables before power off. which is essential for this situation.

But you do not need it now while you are debugging the timer code.

Get the timer code working first, then the motor switching code, then the adc code, then the voltage check code, then the EEPROM save code. Do them one at a time.

When they are all working correctly separately, only then can you start putting them together one piece at a time.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Vcc = (1.1 * 255) / adc_data; 

Are divide and conquest strategies that efficient.

Quote:
i need to store the variables before power off. which is essential for this situation.

No

First you need to have your timers working.

Secondly you need to divide your project into small parts, that you can test methodically and debug and small enough people can detect unpleasant features, if any remain, without efforts.

Thirdly, if the state of your variables needs to be kept even when there is a powxer failure, you can manage to have your MCU (not the pumps) being fed by a battery even if there are no mains : variables are kept automagically (unless the mains are so unreliable your pumps should to be powered by horses/elephants/mammoouths/dinosaurs)....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Vcc = (1.1 * 255) / ADC;
		if(Vcc<4)
		{
			commit_data_to_EEPROM();
		}

when compiler point arrive at this code the s/m become hang and restart.
i think the problem hidden between the mathematical calculation
*float vcc

is i need any math header to do this?

updated
my timer section works correctly but when i insert the adc_it restarts?

Last Edited: Tue. Jul 31, 2012 - 10:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You must make sure the threshold is higher then brown-out-detector, if you have one. Recommended to turn it on if you use EEPROM.

But, like I said before, I would not go this route. Too complicated. Just save your variables once an hour.

And as it's coded now, if VCC stays below that threshold, it will continuously write the EEPROM, possibly wearing it out in minutes. Like Clawson warned of before.

And if this is a real job, what's your job title?

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

Quote:
my timer section works correctly but when i insert the adc_it restarts?

Do no insert the adc_it, add a battery (then, your variables will be kept and you can store your variables into EEPROM every hour).

BTW, your conversion is wrong. you should multiply instead of divide and divide instead of multiplying .
And float arithmetic are not required, if you test being above/under a threshold.
But, with a battery, your troubles will be over....

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

jayjay1974 wrote:
You must make sure the threshold is higher then brown-out-detector, if you have one. Recommended to turn it on if you use EEPROM.

But, like I said before, I would not go this route. Too complicated. Just save your variables once an hour.

And as it's coded now, if VCC stays below that threshold, it will continuously write the EEPROM, possibly wearing it out in minutes. Like Clawson warned of before.

And if this is a real job, what's your job title?


brown out detection is disabled.
i only want to save the details into eeprom only when my Vcc become below 4V(it can be setted to a low value)but every minute i check for Vcc.

but it doesn't work correctly.

Last Edited: Wed. Aug 1, 2012 - 04:48 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why jump through hoops doing things that you don't quite understand and potentially lead to more problems?

Vcc = (1.1 * 255) / ADCL;
if(Vcc<4)...

->

if (Vcc < SOME_ADC_RAW_VALUE_CONSTANT_THAT_INDICATES_4V)...

Why is Vcc a global variable - do you really use it elsewhere?

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

I suppose ADCL are the unsignificant bits of ADC (dividing by it could lead to dividing by zero at random times!) ,
ADCH being the significant ones...
the whole "processing" of the analogic converter looks like a terrible mess , and therefore should be dropped away and replaced by a BATTERY, which will quietly keep all the variables until some mains appear....

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

Quote:
BTW, your conversion is wrong. you should multiply instead of divide and divide instead of multiplying .

from datasheet
ADC=(Vin*255)/Vref

in my case Vin=Vcc,Vref=1.1V(internal)
then ADC=(Vcc*255)/1.1

therefore Vcc=(ADC*1.1)/255

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Vcc = (1.1 * 255) / ADC; 

01:20 PM
!=

Vcc=(ADC*1.1)/255

12:47 PM

AND
what are ADCL? ADCH?

This looks like the definition of a terrible, unuseful mess....

I wrote unuseful because you ***forgot*** to analyse the consequences of feeding the MCU with a battery :
as it may last days (2AH with less than 50 mA ) , your variables are carefully kept : no need for ADC, no need for EEPROM

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

havoooooo........
at last i decided to omit the vcc monitoring section
and i would like to store required variables every 10 minutes
1 hour=6 write
1day=6*24=144 writes
1,000000/144=6944 day=19years life for eeprom
thats enough to me
thanks for all freaks who help me.

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

here is final code. it works fine in avr studio.
one again thanks to all freaks.....

Last Edited: Wed. Aug 1, 2012 - 05:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

one more feature to add to this code is that make a reset switch which clear saved eeprom memory and start the code from begining.

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

dbrion0606 wrote:

Vcc = (1.1 * 255) / ADC; 

01:20 PM
!=

Vcc=(ADC*1.1)/255

12:47 PM

AND
what are ADCL? ADCH?

This looks like the definition of a terrible, unuseful mess....

I wrote unuseful because you ***forgot*** to analyse the consequences of feeding the MCU with a battery :
as it may last days (2AH with less than 50 mA ) , your variables are carefully kept : no need for ADC, no need for EEPROM

using battery is a good decision
but to take that decision , client didn't give me that permission.
see my updated code

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
      minute++;
      if(minute%10==0)
      {
         commit_data_to_EEPROM();
      }
      if(minute==59)
      {
         hour++;
         minute=0; 

might be replaced by

      minute++;
      if(minute==59)
      {
         hour++;
         minute=0; 
....
       }
       if(minute%10==0)
      {
         commit_data_to_EEPROM();
      }

to be sure that, even when you change hour (minute == 59) , things are stored every 10 minutes....

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

justinjohney wrote:

	...
	second++;
	if(second==59)
	{
		second=0;
		minute++;
		...
		if(minute==59)
		{
			hour++;
			minute=0;
			...
		}
	}	
}

here is final code. it works fine in avr studio.
one again thanks to all freaks.....

You really sure that checking against 59 is the right thing to do?

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

thank you
MartinM57

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

Today they said 670 million Indians were in a blackout because the farmers were all running irrigation motors. Man I hope we didnt give Justin the idea that he could just start up these giant motors. Man its a small interconnected world aint it?

Imagecraft compiler user

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

to set the time and selection of motor using lcd interface is really tough for a beginner ............

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

removed

Last Edited: Fri. Aug 3, 2012 - 07:10 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

in my studio when we double click at the errors or warning it does not go to compiler page
only to source code
how can i set avr studio?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
minute=eeprom_read_byte((uint8_t)&saved_minute); 

Why have you put (uint8_t) in that? That is why you are getting a warning as you are converting a pointer to an integer when the parameter of the function DOES expect a pointer.

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

../lcdsample.c:147
What is the content of lcdsample.c
Is it a good idea to name a file with a name which has no logical link?
Are relays and timers (this topic) logically linked with lcds?
NB:if you start a new topic, as this one seemed to work somehow -at least yesterday!- ,
people wonot have to read 5 (to day : may be it gets longer) pages and might be happier (and less confused with details, thus more efficient) helping you....

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

thanks clawson
but that one error still there

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

Well you need to learn how to read an error: It looks like:

../lcdsample.c:147:941: error: expected identifier or '(' before '}' token 

This tells you it is line 147 of the file lcdsample.c, so exactly what does that line say? (it's not easy for us here to know which line is line 147).

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

The code you posted at 11h45 has an unuseful curly brace at| before line 128 (under vi(m), type % to see whether curly braces match;
indent detects it, too). ISR(TIMER1_COMPA_vect) seems to end twice!
I bet it is enough to make avr-gcc very angry! Perhaps you might delete it...

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

Apart from your extra ending curly brace '}', there are annoying things in your code :

I bet (and know it will be out of topic) you will try to use an LCD and some buttons to know and manually change the state/numero of the working motor.

This can be achieved by a pushbutton to increase the motors'numero, another to decrease and a third pushbutton to validate. If pushbuttons are polled every second (and the LCD updated consequently), this might seem slow and unpleasant and ticks/interruptions of say, 100 mseconds might be more comfortable: perhaps you will be tempted by having a timer interrupt every 1/10 second (instead of 1s) and add a counting loop and a variable (let it be called "deciseconds" and seconds are upgraded every time deciseconds go above 10 and need to be zero again)?
Then, you might add the following for each button: if the button is low, a counter is set to low; if it is high, the counter is increased in the interrupt service ;
in the main loop, if a buttons counter is above two -it is somehow debounced-, the corresponding action is done (increase/decrease the desired numero; if validation, the desired numero becomes the real status).

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

Quote:
I bet (and know it will be out of topic) you will try to use an LCD and some buttons to know and manually change the state/numero of the working motor.

Ya
i'm trying to program it.
one doubt:-
in my case one button (EXTINT0)lead to set the time.
i need to increment or decrement mode . for that i'm considerng other interruptrs.
is the compiler go to another ISR while ina n ISR.

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

you do not need interrupts to know for changes in pushbuttons (if they are bouncing, that would be a waste of CPU time):
you need a faster ticker than a one second one (perhaps 1/10 seconds) every tick, you look at each button to see whether it is on
(and then, you increment its counter;
else
its debouncing counter is set to zero):
if its counter is high enough, you suppose the button had no glitches and, in the main loop, you do what you want to be done....
But the ergonomy of such an interface should be discussed, too (I think you need 3 buttons, one to increase the numero of the selected motor, another to decrease it and a third to validate the choice).
And this thread is large enough to shy away any newcomer which might have better ideas - > you should open a new thread...

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

edited

Last Edited: Mon. Aug 6, 2012 - 04:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Justin. Did you see my challenge in the last message of the other thread about beginning avr?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
have any idea

Do one thing at a time.

Do one topic at a time (and finish it!)

If you want to change topic, open a new thread:
people wonot be shyed away by pages and pages (FYI, I feel and fear this thread is not finished, as there are things which might be better coded for "timer and relays" - the title of the thread)
New people will come and give you new/better ideas.

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

To be honest, I wouldn't bother with a LCD and buttons at all.

Just three LEDs that indicate which motor is currently running, and a dip switch to set each motor running time. Like three four switch dip switches. Good enough to set 16 different values for each motor.

How often are you going to change the running times to warrant a more complicated user interface?

This is one of those devices you install, set up once, and then forget about.

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

edited

Last Edited: Mon. Aug 6, 2012 - 04:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Come on...! :roll:

What's the error the compiler reports? Motor_off misses the closing bracket.

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

edited

Last Edited: Mon. Aug 6, 2012 - 04:50 AM

Pages

Topic locked