how do i count pulses using timer 0?

Status
Not open for further replies.

vortech1

New Member
i need a pulse counter software in picbasic so i could implement a clock/direction stepper motor driver using pic16f84.i want my pic board to be like allegro's 5804 stepper motor driver. 5 inputs: direction,clock or step(pulse for this input.every high to low transition the stepper motor would increment step),mode (2 pin input) 00 for 2 phase,01 for full,10 for half and 11 for step inhibit,output enable.

i dont know how to go about the counting and incrementing part.should interrupt be used?

help pls.
-vortech
 

I don't see why you need to count anything - from what I can gather you want two input pins on the PIC, one for direction (so, for example, when high it steps CW, when low it steps CCW), and the other to step the motor - where you input a pulse and the motor moves one step, in the direction set by the other pin.

All that's ever entering the micro is a single pulse - all you need to do is read that input line like you would a switch - when it goes high move the motor on one step (using a data table of moves), then wait for the input pin to go low before going back to wait for a high input again. The direction setting is easily done by checking if the pin is high or low, and reading from the relevent data table (one for CW, one for CCW).
 
thanx for the suggestion but........(follow up question)

pulsing happens very fast i think. is it possible to code in such a way that it reads the port like just a switch?
 
vortech1 said:
thanx for the suggestion but........(follow up question)

pulsing happens very fast i think. is it possible to code in such a way that it reads the port like just a switch?

The pulsing can't happen very fast, it's one pulse per step of the motor, and a stepper motor can't step every fast - certainly not compared with the speed of a PIC!. If you pulse the motor at 1000 steps per second (which is too fast, and it wouldn't move) that gives 1mS between pulses, a 4MHz PIC can execute 1000 instructions in that time, or a 20MHz PIC can execute 5000 instructions.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…