Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

8951 and C programming issues

Status
Not open for further replies.

Opel_Corsa

Member level 1
Joined
Nov 13, 2005
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,614
Please assume the following program structure for a moving bot with 2 motors (using an 8951 chip):

Code:
...corresponding C and 8951 libraries included here...
...some initialization here. also TR0 and EA and ET0 are all set...
...some global variables here, most of which are 'volatile'
void PIcontroller(void); // the controller for making wheels rotate at same speed
void RotationCounter(void); // counts the number of turns of the wheels via 2 rotary encoders connected to each wheel
void forward(void);
void backward(void);
void stop(void);
void turn(void);
void MainController(void) interrupt 1 using 1 // an interrupt is needed for the PIcontroller() and RotationCounter() to work properly, I think
void main(void);

- Almost all of the functions use global volatile variables.
- Each function may call another function. also pins maybe set or clear or may need PWM applied to them (for the motors) in each function. For example, forward() needs to call PIcontroller() and RotationCounter() in order to have some PWM. Then some pins are needed to be configured to use PWM.
- the MainController() interrupt calls each function with some conditions. e.g.

forward() until rotary counters reach 200;
stop();
backward() until rotary counters reach 200;
etc.

- main() would simply call the interrupt in an infinite loop, e.g. while(1) { MainController(); }

Now my question is that does the above coding structure do what it is intended to do? Is it correct coding? Are the interrupts being used correctly? Is there a way to implement the same idea in main() instead of the interrupt function?

P.S> This is not a part of the main question, but would be appreciated if someone could tell why this is happening: in the MainController() interrupt when I call forward() the bot moves forward alright. But when I call forward() again, it acts weird (e.g. both wheels start going backwards with very low PWM value)...
 

Hi

You say nothing about your c compiler ???
Could you explain what event start your interrupt? In what pin? Level or Edge?

be aware that usually you can't call functions from an Interrupt.
You would change the way to solve the problem (for instance using flags)

Hope this help.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top