Hi all, One of my biggest problems has always been using the internal timers of the PICs. I'm using a pic16f870 for this little project, and am running into a problem, I think it's the way I have setup my timers/interrupts, but I am not sure - I'm hoping someone can enlighten me before I get much farther into the code. Basically, the code is designed to count up on port A ~ every ms. The timer overflow happens ~ .1ms, I have a counter that increments every time the interrupt is triggered. This is being done with Timer0 My second timer is causing an interrupt every ~4us, allowing me to turn on and off bits on port C for any length of time from 0 time on to 250 increments of time on. But, it doesn't seem to want to toggle, I'm thinking port A toggling is the problem - by the time I can see everything on my scope, port C is fixed low, which *might* imply that the counter I have in the second interrupt has exceeded my set counts and is now perma-low. But I am not sure. I have programmed this in CCCS' C, here is the source... // setup by CCCs #include <16F870.h> #device adc=8 #use delay(clock=20000000) #fuses HS,NOWDT,NOLVP // structure for dutycycles typedef struct _DC { int8 Duty1, Duty2, Duty3; int8 dc1,dc2,dc3; int1 curphase1, curphase2, curphase3; }stDutyCycle; int8 curselect, curedit; //unused int8 count; int8 curstate, prevstate ;// unused stDutyCycle DC[3]; #int_RB RB_isr() { /* RB_ISR was created by compiler, but I wanted timer0 used instead, this could be part of my problem, not sure. int8 B; B = input_b(); if (b if (b&0x01) { if (toggled) toggle = 0; } else { curedit++; if (curedit == 3) curedit = 0; toggled = 1; }*/ } #int_TIMER2 TIMER2_isr() { DC[curselect].dc1++; DC[curselect].dc2++; DC[curselect].dc3++; if (DC[curselect].dc1>DC[curselect].Duty1) output_low(PIN_C0); if (DC[curselect].dc2>DC[curselect].Duty2) output_low(PIN_C1); if (DC[curselect].dc3>DC[curselect].Duty3) output_low(PIN_C3); } #int_TIMER0 TIMER0_isr() { count++; if (count==9) { count = 0; DC[curselect].dc1 = DC[curselect].dc2 = DC[curselect].dc1 = 0; output_c(0x00); if (curselect == 2) curselect = 0 ; else curselect++; output_a(curselect); if (DC[curselect].Duty1>0) output_high(PIN_C0); if (DC[curselect].Duty2>0) output_high(PIN_C1); if (DC[curselect].Duty3>0) output_high(PIN_C2); } } void main() { count = curselect = 0; DC[0].dc1 = DC[0].dc2 = DC[0].dc3 = DC[1].dc1 = DC[1].dc2 = DC[1].dc3 = DC[2].dc1 = DC[2].dc2 = DC[2].dc3 = 0; DC[0].Duty1 = 150; DC[0].Duty2 = 180; DC[0].Duty3 = 100; DC[1].Duty1 = 0; DC[1].Duty2 = 180; DC[1].Duty3 = 130; DC[2].Duty1 = 100; DC[2].Duty2 = 130; DC[2].Duty3 = 0; set_tris_a(0x00); set_tris_c(0x00); setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_spi(FALSE); //setup_counters(RTCC_INTERNAL,RTCC_DIV_2); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DIV_BY_1,20,1); //enable_interrupts(INT_RB); enable_interrupts(INT_TIMER2); enable_interrupts(INT_TIMER0); enable_interrupts(global); output_a(0); output_c(0); while (1); } Any suggestions would be most appreciated. -Tony -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.