Hi I'm using a 16F627 programmed with PICC Lite as part of a R/C speed controller for a friend. I'm using the internal oscillator, an LED+resistor so that I can see if the thing's working and a 555 to simulate the output from the receiver. Other than a battery, that's the complete hardware. My configuration word is 0x3F19: BOD, MCLR, LVP & all timers disabled. INTRC with clock out. The code seemed to be progressing nicely, when I came across a peculiar problem: the output PWM signal was going "bonkers". After some thinking and experimenting, I added the two lines (marked /** 1 **/) to generate 1 single 1us pulse before the main loop. As I suspected, this pulse is emitted more than the once it should be (but read on...). After more experimentation, I discovered that if the code between /** 2 **/ and /** 3 **/ is present, I get multiple resets, and it's absent, I do not. Two different F627's give the same results (which are repeatable). Looking at the generated assembler (included below the C program), I cannot see anything wrong and I would appreciate any advice you may have. Thanks for reading. ===Relevant parts of the C program=== |#include | |#define byte unsigned char | |#define readbit(PORT, BIT) ((PORT) & (1<<(BIT))) |#define setbit(PORT, BIT) ((PORT) |= (1<<(BIT))) |#define clearbit(PORT, BIT) ((PORT) &= ~(1<<(BIT))) |#define flipbit(PORT, BIT) ((PORT) ^= (1<<(BIT))) | |//PORTB bits | |#define PULSIN 0 // servo pulses in |#define FLASHOUT 1 // regular pulses (approx 0.7Hz) |#define INITPULSE 2 // pulses once during init |#define PWMOUT 3 // PWM out | |void main(void) |{ | byte flasher = 0; // count input pulses | | // setup ports | | PORTA = PORTB = 0; | TRISA = TRISB = 0; | setbit(TRISB, PULSIN); | | // single pulse during init only | | setbit(PORTB, INITPULSE); /** 1 **/ | clearbit(PORTB, INITPULSE); | | // here we go! | | for ( ; ; ) | { |/** 2 **/ | if (flasher++ >= 30) | { | flipbit(PORTB, FLASHOUT); | flasher = 0; | } |/** 3 **/ | } |} ===Assembler generated=== | INCF desired, 1 | DECF desired, 0 | MOVWF btemp | MOVLW 0x1E | SUBWF btemp, 0 | BTFSS STATUS, 0 | GOTO 0x3AE | MOVLW 2 | XORWF PORTB, 1 | CLRF desired |0x3AE: -- Please, no CC's - I read the list. -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body