NetBurner SAME70 Stepper Motor Step Count Example
Overview
This example demonstrates an advanced stepper motor control system using the NetBurner SAME70 platform's sophisticated timer coordination capabilities. The application uses three interconnected timer channels to create a complete stepper motor driver with precise step counting, programmable frequency control, and hardware-based pulse generation.
Supported Platforms
Features
- Multi-Timer Coordination: Uses three synchronized timer channels working together
- Precise Step Counting: Tracks and counts individual step pulses with completion detection
- Variable Frequency Control: Programmable step rates from low to high frequencies
- Large Step Count Support: Handles step counts up to millions through interrupt-driven management
- Bidirectional Control: Software-controlled direction (up/down counting)
- Hardware-Based Generation: Timer hardware generates consistent pulses independent of CPU load
- Real-Time Command Interface: Interactive serial console for dynamic control
- Advanced Timer Cross-Coupling: Sophisticated timer interconnection for coordinated operation
- Completion Synchronization: Semaphore-based notification when step sequences complete
Hardware Configuration
Pin Assignments
MODM7AE70:**
- P1.8: TIOA8 (Timer channel A output - primary step pulses)
- P2.6: TIOB8 (Timer channel B output - secondary output/direction)
Timer Architecture
Timer Coordination System:
+------------------+ Cross-Trigger +-------------------+
| Frequency Timer | Connection | Pin Control Timer |
| (Timer 6) |-------------------->| (Timer 8) |
| Generates PPS | | Stepper Mode |
+------------------+ | Hardware Pulses |
| +-------------------+
| Clock Signal |
v | Step Pulses
+------------------+ v
| Step Count Timer | +-------------------+
| (Timer 7) | | Stepper Motor |
| Tracks Progress | | Controller |
| Interrupt-Driven | | Hardware |
+------------------+ +-------------------+
Timer Channel Assignments
- Timer 6 (TIMER_STEP_FREQ): Frequency generation and base timing
- Timer 7 (TIMER_STEP_COUNTER): Step count management and completion tracking
- Timer 8 (TIMER_STEP_PINS): Hardware pulse generation and stepper mode control
Application Flow
System Startup
|
v
Initialize Hardware
|
v
Configure Pin Functions
|
v
Allocate Timer Resources
|
v
Setup Timer Cross-Coupling
|
v
Main Command Loop
|
v
+-------------------------+
| User Command Input |
| <steps>,<rate>,<dir> |
+-------------------------+
|
v
Parse and Validate Command
|
v
Configure Timer Parameters
|
v
+----------+----------+
| | |
v v v
Frequency Count Pin
Timer Timer Timer
Setup Setup Setup
| | |
+----------+----------+
|
v
Synchronized Timer Start
|
v
Hardware Pulse Generation
|
v
Interrupt-Driven Counting
|
v
Wait for Completion Signal
|
v
Display Results
|
v
Return to Command Loop
User Interface
The application provides an interactive command-line interface for real-time stepper motor control.
Command Format
<step count>,<steps per second>,<U/D>
Parameters:**
- step count: Total number of steps to execute (positive integer)
- steps per second: Step frequency/rate (positive integer)
- direction: 'U' or 'u' for up counting, 'D' or 'd' for down counting
Usage Examples
> 3000,300,D
Execute 3000 steps at 300 steps per second, counting down
> 30000,2000,U
Execute 30000 steps at 2000 steps per second, counting up
> 500000,1000,D
Execute 500000 steps at 1000 steps per second, counting down
Operation Sequence
- System prompts with
>
- User enters command in specified format
- System validates input parameters
- If valid, stepper sequence begins immediately
- System waits for completion (blocking operation)
- Upon completion, displays actual step count achieved
- Returns to prompt for next command
Key Technical Features
Multi-Timer Coordination
The application implements a sophisticated three-timer coordination system:
Timer Interconnection:**
- Frequency timer generates the base clock signal
- Pin timer receives frequency timer output via cross-coupling
- Count timer tracks step progression using interrupt callbacks
- All timers operate from the same timer block for proper cross-coupling
Large Step Count Support
Handles step counts beyond 16-bit timer limitations through intelligent phase management:
Step Count Phases:**
- Phase 1 (< 65,536 steps): Direct single-timer configuration
- Phase 2 (65,536 - 69,631 steps): Two-phase interrupt management
- Phase 3 (> 69,631 steps): Multi-phase interrupt-driven counting
Clock Source Optimization
Automatically selects optimal clock source for requested frequency:
Available Clock Sources:**
- PCK6 (Programmable Clock 6)
- PERIPH_CLOCK/8
- PERIPH_CLOCK/32
- PERIPH_CLOCK/128
Selection algorithm minimizes frequency error for best timing accuracy.
Hardware Stepper Mode
Timer 8 operates in dedicated stepper mode providing:
- Automatic step/direction signal generation
- Hardware-controlled pulse width and timing
- Gray code sequence generation
- Direction control via software commands
Important Notes
Hardware Requirements
- All three timer channels (6, 7, 8) must be from the same timer block
- Timer cross-coupling requires specific timer block architecture
- Pin functions must be properly configured for timer outputs
Platform-Specific Considerations
- MODM7AE70: Uses Timer Block 2 (channels 6, 7, 8)
- Pin Conflicts: Some pins may conflict with other peripheral functions
- Clock Configuration: PCK6 requires proper system clock setup
Operational Characteristics
- Timing Precision: Hardware timers provide microsecond-level accuracy
- CPU Independence: Once started, pulse generation continues without CPU intervention
- Interrupt Overhead: Step counting uses low-priority interrupts for minimal system impact
- Completion Detection: Semaphore-based synchronization ensures reliable completion notification
Limitations and Considerations
- Maximum practical step frequency limited by timer clock sources
- Very high step counts may take significant time to complete
- Command interface blocks until step sequence completion
- Timer resource allocation must succeed for proper operation
Application Areas
This example is particularly valuable for:
Industrial Applications
- CNC machine tool control systems
- Automated manufacturing equipment
- Precision positioning systems
- Assembly line automation
Robotics Applications
- Multi-axis robot control
- Precision servo positioning
- Automated pick-and-place systems
- Mobile robot wheel control