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.

pic16f690 interrupt not working

Status
Not open for further replies.

ermias20

Newbie level 3
Newbie level 3
Joined
Aug 11, 2014
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
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 */ 
         }
    }
}


:p
 

Thanks udayan92 I tried so many things but never activated the interrupt(ISR) pls help
 

In line 41, I switch from 0x8b to 0x89, the Go and adon was turn on at the same time. My problem is the isr activated once at rest only. Ones in the while loop, does not interrupt to read the pot.
Code:
 

hello,

your ISR interrupt does nothing !

Maybe it is more interresting to use timer0 (or other timer) interrupt to count elementary delay
and use ADC reading to do PORTD output every with : ADC value * elementary timing
or directly use 255-Adc_value (8bits) for TMR0 target. to elaborate the delay..
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top