<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
<div>Hi all,</div><div><br></div><div>Michael is correct to show concern for the busy wait code. The USB function is often polled in the PIC library, and a long 500ms, 100ms, or even just a few milliseconds delay would cause the device to disconnect from the host. It's theoretically possible to run USB from an interrupt, but I'm not sure this works yet. Most all of the projects I've seen that implement PIC USB are using the polled USB stack. At the very least, it would be good to be prepared for that setup.</div><div><br></div><div>It would be much better to design a generic mechanism for timed events so that all of the existing delay100() calls can be removed when necessary. I'm looking ahead to v3 when you add USB. Right now, I'm sure there's no problem since, as you point out, all the other peripheral communications are interrupt-driven.</div><div><br></div><div>Note that the 100ms delay is not very accurate when all of those other interrupts are happening. Not that accuracy is that important, but a timer-based solution would not slow down in the presence of significant interrupt activity.</div><div><br></div><div>Brian</div><div><br></div><br><div><div>On Sep 5, 2013, at 05:58, Mark Webb-Johnson wrote:</div><div><blockquote type="cite"><div><div>We have several of those already in the code.</div><div><br></div><div>The UART, CAN and LEDs are all interrupt-driven, so will run even in a delay100() sleep - apart from those there shouldn't be anything else timing-dependant.</div><div><br></div><div>That said, 500ms is quite a long time, and for this example it would also be quite simple to do it in ticker1() (for a 1000ms delay), or even ticker10th() (which is called every 100ms).</div><div><br></div><div><div><div>On 5 Sep, 2013, at 5:57 PM, Michael Jochum <<a href="mailto:mikeljo@mac.com">mikeljo@mac.com</a>> wrote:</div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>i don't like this:</div><div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px; "> delay100(5);</blockquote></div></blockquote><div><div>in a "real Time System"</div><div><br></div><div>Better to put a sub in an timer/interrupt routine.</div><div>I think we have enough timer.</div><div><br></div><div>Bye</div><div>Michael</div><div><br></div><div>Am 05.09.2013 um 10:29 schrieb Mark Webb-Johnson <<a href="mailto:mark@webb-johnson.net">mark@webb-johnson.net</a>>:</div><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I think I'd like to keep utils.{h,c} simple. Just have standardised functions to set the digital output on/off.</div><div><br></div><div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>void io_digital_set(port, onoff);</div><div>unsigned char io_digital_get(port);</div></blockquote></div><div><br></div><div>Then, put the logic for how it is used in the vehicle module itself.</div><div><br></div><div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>if (io_digital_get(4)==0)</div><div> {</div><div> io_digital_set(4,1);</div><div> delay100(5);</div><div> io_digital_set(4,0);</div><div> }</div></blockquote></div><div><br></div><div>We would also need to initialise the ports in the correct way, and standardise what ports are used for input and what for output. I will look at this later tonight.</div><div><br></div><div>Regards, Mark.</div><div><br><div><div>On 5 Sep, 2013, at 3:14 PM, Håkon Markussen <<a href="mailto:hakon.markussen@gmail.com">hakon.markussen@gmail.com</a>> wrote:</div><blockquote type="cite"><div dir="ltr"><div><div><div>I'm sorry that my programming skills are not the best and have to ask about this. But to get this baby going I need some more detailed help.<br><br></div>In the utils.c (and utils.h) can I add two functions, and then call them from the vehicle-specific?<br> </div>One function (lock) sets RB4 high for 500ms and the other fuction (unlock) sets RB5 high for 500ms.<br><br></div>Do you think this will work?<br><div><br>void send_lock(void)<br> {<br> // Check if RB4 is low, set RB4 high for 500ms and back to low<br> if (PORTBbits.RB4 == 0)<br> {<br> PORTBbits.RB4 = 1;<br> delay100(5);<br> PORTBbits.RB4= 0;<br> }<br><br>void send_unlock(void)<br> {<br> // Check if RB4 is low, set RB4 high for 500ms and back to low<br> if (PORTBbits.RB5 == 0)<br> {<br> PORTBbits.RB5 = 1;<br> delay100(5);<br> PORTBbits.RB5 = 0;<br> }<br></div></div></blockquote></div></div></div></blockquote></div></div></div></blockquote></div></div></div><br></blockquote></div></div></body></html>