Showing posts with label microcontroller experiment. Show all posts
Showing posts with label microcontroller experiment. Show all posts

Tuesday, January 5

Stepper Motor Drive

The Experiment 5 we will test Use PIC16F628 to Drive Stepper Motor, for Article & Types of Stepping Motors you and see links as Resources ,Tools & Related Menu below
This Experiment use Unipolar Motors 9-24 V 7.5 Degree/Step , and use IC ULN2003 for Drive




Assemble circuit as figure 5.1 and Download Program to PIC16F628 from Figure 5.1 VR 100k use for adjust frequency clock of PIC16F628 when run in mode ER
Source Code For Experiment 5

list p= 16 f 628 ; list directive to define processor
#include

; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _ER_OSC_NOCLKOUT & _MCLRE_ON & _LVP_OFF
COUNT equ 0 x 20
DUMMY 1 equ 0 x 21
DUMMY 2 equ 0 x 22
org 0 x 000 ; Reset Vetor Address
bsf STATUS,RP 0 ; Set RB 4- RB 7 For Drive Stepper Motor
movlw b' 00001111 '
movwf PORTB
bcf STATUS,RP 0
Begin movlw .12 ; Loop 12 Time For 7.5 Degree/Step
; 4x12x7.5 = 360
movwf COUNT
Loop movlw b' 00010000 ' ; 1 Phase Full Step
movwf PORTB
call Delay ; Change Delay For Change Speed
movlw b' 00100000 '
movwf PORTB
call Delay
movlw b' 01000000 '
movwf PORTB
call Delay
movlw b' 10000000 '
movwf PORTB
call Delay
decfsz COUNT,f ; Check Loop = 12 Time ?
goto Loop ; If Not Loop Again
movlw .12 ; Reverse Move 12 Time
movwf COUNT
Loop 2 movlw b' 01000000 '
movwf PORTB
call Delay
movlw b' 00100000 '
movwf PORTB
call Delay
movlw b' 00010000 '
movwf PORTB
call Delay
movlw b' 10000000 '
movwf PORTB
call Delay
decfsz COUNT,f ; Check Loop = Time ?
goto Loop 2
goto Begin ; If Yes Start Again
Delay movlw 0 x 20 ; Delay Between Step
movwf DUMMY 1
Delay 1 clrf DUMMY 2
decfsz DUMMY 2 ,f
goto $-1
decfsz DUMMY 1 ,f
goto Delay 1
return
END ; end of program


Tools & Components
Name List Quantity
MPLAB -
PIC16F628 1
4MHz Crystal 1

Push Button Switch 1 PC 1
33pF Capacitors 2
4.7K Resistors 1
47K Resistors 1
100K Variable Resistors( VR) 1
ULN2003 1
Unipolar Motors 1

Sound Melody

The previously experiment (Exp 3) we can Generated Sound at one frequency, for this experiment we will apply Exp 3 to Generated Sound more one frequency like melody
Assemble circuit as figure 4.1 and Download Program to PIC16F628


Source Code For Experiment 4

list p= 16 f 628 ; list directive to define processor
#include

;processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF
COUNT equ 0 x 20
SETTIME equ 0 x 21
org 0 x 000
clrf PORTA ; Initial PORTA
; output data latches
movlw 0 x 07 ; Turn Comparator off and
movwf CMCON ; Enable pins for I/O
bsf STATUS,RP 0 ; Select Bank 1
movlw 0 x 0 F ; RA 0- RA 3 = Input RA 4 = Output
movwf PORTA ;
bcf STATUS,RP 0 ; Return to Bank 0
Loop1 bsf PORTA, 4 ; Start Rising Pulse
call Delay ; Delay
bcf PORTA, 4 ; Falling Pulse
call Delay
btfsc PORTA, 3 ; Test RA 3 Press
goto Check 2 ; If No Continue Check
movlw 0 x 20 ; If RA 3 Press Set Time = 20 H
movwf SETTIME
goto Loop1 ; Continue
Check 2 btfsc PORTA, 1 ; Test RA 1 Press
goto Check 1 ; If No Continue Check
movlw 0 x 55 ; If RA 1 Press
movwf TIME ; Set Time = 55 H
goto Loop1 ; Continue
Check 1 btfsc PORTA, 0 ; Test RA 0 Press
goto Loop1 ; If No Begin Pulse Again
movlw 0 x 60 ; If RA 0 Press
movwf TIME ; Set Time = 60 H
goto Loop1 ; Begin Pulse Again

Delay movf TIME,w ; Delay Use Change Delay Time
movwf COUNT ; With TIME Register
decfsz COUNT,f
goto $-1
return

END ; of program


Tools & Components
Name List Quantity
MPLAB -
PIC16F628 1
4 MHz Crystal 1
Push Button Switch 1 PC 4
33 pF Capacitors 2
4.7K Resistors 1
1K Resistors 3
220 Resistors 3
PIEZO 1
LED 3

Sound Generated

The Experiment 3 we will Generated sound (one frequency) by use PIC16F628 . first of all see Timing Diagram as figure 3.1 for to understand



Assemble circuit as figure 3.2 and load Program to PIC16F628 . RA4 Connect with PIEZO , The Frequency can be calculate by formula as below

f = 1/ T
1/(768 uSec + 768 uSec) = 651 Hz



Source Code For Experiment 3

list p= 16 f 628 ; list directive to define processor
#include

; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF

org 0 x 000
clrf PORTA ; Initial PORTA
; output data latches
movlw 0 x 07 ; Turn Comparator off and
movwf CMCON ; Enable pins for I/O
bsf STATUS,RP 0 ; Select Bank 1
movlw b' 11101111 ' ; RA 4 = Output
movwf PORTA ; Other = Input
bcf STATUS,RP 0 ; Return to Bank 0
Loop1 bsf PORTA, 4 ; High RA 4 768 usec
call Delay
bcf PORTA, 4 ; Low RA 4 768 usec
call Delay
goto Loop1 ; Frequency = 1/(768 usec + 768 usec)
; = 651 Hz
Delay clrf 0 x 20 ; Delay 768 usec
decfsz 0 x 20 ,f
goto $-1
return
END




Tools & Components



Name List Quantity
MPLAB -
PIC16F628 1
4MHz Crystal 1
Push Button Switch 1 PC 1
33pF Capacitors 2
4.7K Resistors 1
1K Resistors 1
PIEZO 1

Input & Output on Port A

The Experiment 2 we will test Port A is both Input and Output . Assemble circuit as figure 2.1 and Download Program to PIC16F628



Source Code For Experiment 2

list p=16f628 ; list directive to define processor
#include ; processor specific variable definitions

__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF

org 0x000
clrf PORTA ; Initial POR TA
; output data latches
movlw 0x07 ; Turn Comparator off and
movwf CMCON ; Enable pins for I/O
bsf STATUS,RP0 ; Select Bank 1
movlw b'11111111' ; All PORTA = Input
movwf PORTA ;
bcf STATUS,RP0 ; Return to Bank 0
btfsc PORTA,0 ; Test Switch Press ?
goto $-1 ; If Not Press Loop
bsf STATUS,RP0 ; If Press Set RA0 = Output
bcf PORTA,0 ; TRISA
bcf STATUS,RP0 ; Return To Bank 0
bcf PORTA,0 ; RA0 = 0 LED "ON"
goto $
END ; end of program'




Tools & Components


Name List Quantity
MPLAB -
PIC16F628 1
4MHz Crystal 1
LED 1

Push Button Switch 1 PC 2
33pF Capacitors 2
4.7K Resistors 1
1K Resistors 1

Test Port A Bit 0 ON LED

First Experiment we will test Port RA by on RA0 that connect to LED the schematic for Experiment 1is shown below in Figure 1



Assemble circuit as figure 1.1 and load Programming to PIC16F628 after that on power supply you will see result it


Source Code For Experiment 1



list p=16f628 ; list directive to define processor
#include ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF

org 0x000
clrf PORTA ; Initial PORT A
; output data latches
movlw 0x07 ; Turn Comparator off and
movwf CMCON ; Enable pins for I/O
bsf STATUS,RP0 ; Select Bank 1
movlw b'11111110' ; All PORTA = Input
movwf PORTA ; RA0 = Output
bcf STATUS,RP0 ; Return to Bank 0
bcf PORTA,0 ; RA0 = 0 LED "ON"
goto $

END ; end of program'



Tools & Components

Name List Quantity
MPLAB -
PIC16F628 1
4 MHz Crystal 1
LED 1
33pF Capacitors 2
1K Resistors 1
4.7K Resistors 1
Push Button Switch