ermias20
Newbie level 3
- Joined
- Aug 11, 2014
- Messages
- 4
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 31
I am using pic 16f690 to run stepper motor and I want to control the speed by potentiometer. I use interrupt but the speed of the motor do not change(the interrupt) never active. here is my code pls help.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 #include <PIC16F690.h> #include <pic.h> #include <htc.h> #define _XTAL_FREQ 20000000 define FOSC 8000000L /* The Delay Function */ #define delay_us(x) { unsigned char us; \ us = (x)/(12000000/FOSC)|1; \ while(--us != 0) continue; } void delay_ms(unsigned int ms) { unsigned char i; do { do { delay_us(1);//change from 164 to 10 } while(--i); } while(--ms); } void readArray(int); void interrupt isr(); int delay = 3; void interrupt isr() { if (ADIF == 1) { ADIF = 0;} } void main() { OSCCON = 0x70; /* Select 8 Mhz internal clock */ TRISA = 0x04; // set RA2 to input, 0000 0100 TRISB = 0x00; /* Set All on PORTB as Output */ TRISC = 0x00; /* Set All on PORTC as Output */ ANSEL = 0x04; // RA2 as analague input ADCON1 = 0x70; // ADC Frc clock ADCON0 = 0x8b; // bit 5-2 CHS<3:0>: Analog Channel Select bits 0000 = AN0,0001 = AN1 0010 = AN2, right justified INTCON = 0xc0; PIR1 = 0X00; PIE1 = 0x40; delay_ms(20); ADCON0 = ADCON0 |(1<<1); while(ADCON0&(1<<1)) { } delay = (ADRESH << 8) + ADRESL; for(;;) { for (int e = 0; e < 4; e++) { delay_ms(delay); int intarray[4] = {0x0a,0x09,0x05,0x06};//3= black, 6 = black, 11 = brown, 14 = yellow PORTC = intarray[e]; /* Tur2n On Port RC0 */ } } }