|
|
View previous topic :: View next topic |
Author |
Message |
Salenko
Joined: 08 Sep 2008 Posts: 84
|
PortB interruption problem when command a stepper motor |
Posted: Mon Oct 06, 2008 11:14 am |
|
|
hi all,
I made a code to generate a varied clock signal in order to drive a stepper motor through the L297 and L298 IC,
I use two Push buttons :
one to increase the speed of the motor with (linked to the external interruption RB0)
the other: to slow it down (connected to RB7)
the first one runs well, while the second block the simulation (ISIS), does the problem comes from a conflict between the two interruptions routines ??? or from the RB routine itself ??
can anybody give me a hand to figure out ther source of the problem
here is my source code:
PIC: 16F876
Compiler:PCW 4.057
Code: | #include <16F876.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232 (baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#include "flex_lcd.c"
//=====pins configuration==========
#define choix_pas PIN_B1
#define sens PIN_B2
#define clock PIN_B3
#define vit_up PIN_B6
#define vit_down PIN_B7
//========Variables=======
int inth,int2h,tmp=160,mitmp ; // tmp = period, mitmp= half period
float freq; //
#Priority EXT
#int_ext
void ext_isr()
{
tmp=(int)tmp/2;
inth=1;
}
#int_rb
void rb_isr ( )
{
tmp=(int)tmp*2;
int2h=1;
}
void main()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_ccp1(CCP_OFF);
setup_ccp2(CCP_OFF);
ext_int_edge(0,L_TO_H);
ext_int_edge(7,L_TO_H);
enable_interrupts(INT_EXT);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
lcd_init();
lcd_putc("Speed:"); /7 speed/frequency level
printf("\f tmp=160ms, freq=6.25Hz "); // this is the default frequency signal send to CLOCK input of the L297
while(1)
{
mitmp=(int)tmp/2; // half of period
output_high(clock);
delay_ms(mitmp);
output_low(clock);
delay_ms(mitmp);
if(inth)
{
freq=1000/tmp; // the frequency in Hertz
printf("\f tmp=%i ms, freq=%f Hz ",tmp,freq);
lcd_putc("+");
inth=0;
}
if(int2h)
{
freq=1000/tmp;
printf("\f tmp=%i ms, freq=%f Hz",tmp,freq);
lcd_putc("-");
int2h=0;
}
}
}
|
here is a capture of the simulation after two press of the Up (of clock frequency) button .
I don´t know how to display a float or an integer on LCD, that´s why I represented the frequency increase with ´+´ (I use the flex_lcd.c drive)
any question is welcome to clarify my code,
thanks in advance.
PS: I posted a topic about interruptions conflicts one month ago but the answers did not help me to resolve the problem, that was for another code and schematic but still with the same sources of interruption. hey by the way, is using an interruption routine when pressing a button is the best good way to change the frequency ? or should I use an ordinary Input and poll it ???????
Last edited by Salenko on Mon Oct 06, 2008 12:15 pm; edited 1 time in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Guest
|
|
Posted: Mon Oct 06, 2008 1:01 pm |
|
|
I think that the problem is that the interrupt on change is not clearing after the you exit the int_rb routine. This has happened me before and you can check in the listing.
If it hasn't been cleared, you need to read the port first than clear the flag manually. |
|
|
Guest
|
|
Posted: Mon Oct 06, 2008 2:52 pm |
|
|
what simulator application is the screenshot of?
cheers |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Tue Oct 07, 2008 1:12 am |
|
|
hi pcm programmer and all the group
thank you for reminding me to add:
in the RB interruption routine to end the mismatch condition. the PortB interruption works now (can change with it the frequency and Display it) , but I have now another kind of problem: a press on ´up´ push button generates two interruptions although I add a debounce delay (in the routine) of 50ms. |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Tue Oct 07, 2008 1:13 am |
|
|
Anonymous wrote: | what simulator application is the screenshot of?
cheers |
ISIS of Labcenter |
|
|
Guest
|
|
Posted: Tue Oct 07, 2008 3:34 am |
|
|
thanx |
|
|
Salenko
Joined: 08 Sep 2008 Posts: 84
|
|
Posted: Tue Oct 07, 2008 1:51 pm |
|
|
hi again,
when I simulate my PIC with ISIS I always get this error message
[PIC16ADC] PC=0x0413, ADC conversion clock period (5e-07) is possibly invalid for device clock frequency
can anybody how this error is related to my code (first message in this topic)
knowing that I did not forget to disable the analog ports and the ADC in my program:
Code: | setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF); |
thanks in advance. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|