Hi Rich, On 25/10/2015 06:39, Richard R. Pope wrote: > Hello everyone, > Well I have it working reliably. Now I can't get my delay routines=20 > to work correctly. No matter what I try my delays do not change. How you know this? How you measured the real delay? > Would=20 > someone look at my delay routines and see if they can spot what I am=20 > doing wrong? Here are the routines: > > extern void wait_us(unsigned int delay) > { > for(; delay; delay--) > { > NOP(); //This is about 500 nS at 1 MHz Here one error: at 1 MHz of clock the instruction clock is ever 1/4 so 250 = kHz =3D 4 microseconds. You can find this explained in paragraph 5.2 of datasheet. > //NOP(); //Now we have one uS at 1 MHz > //NOP(); //This is about 500 nS at 1 MHz > //NOP(); //Now we have one uS at 1 MHz > //NOP(); //This is about 500 nS at 1 MHz > //NOP(); //Now we have one uS at 1 MHz > } > } > extern void wait_ms(unsigned int delay) Here "unsigned int" is 16 bit =3D 0..65535 > { > wait_us(delay * 1000); //This gives us 1 millisecond > } > > extern void wait_seconds(unsigned int delay) > { > wait_ms(delay * 1000); //This is one second No! This is an overflow error! 1000*1000 > 65535! Check your compiler settings, this error can be catched at compile time (maybe... no experience with XC8). > } > > Thanks, > rich! :-) Nic * * --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .