Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - prh

Pages: [1]
Webserver Firmware / Boot up hang (Ethernet) and watchdog
« on: July 30, 2014, 09:04:39 AM »
A few topics in one posting.
We have multiple SBC projects based upon circa 2010 netcruzer project code. We are trying to track down some annoying bugs in some of the code branches that manifests in various ways:

1) if the SBC is powered up with an active/ready Ethernet connection already present it will hang completely in the first ~1 second. In this situation power cycling the SBC with Ethernet disconnected, waiting ~5 seconds and then  plugged in the Ethernet cable all is well. (SBC configured for dynamic IP)

2) SBC and a *router* power up at the same time. As router boots after ~20 seconds the SBC is seen at default IP of After a further ~30 seconds the routers DHCP server assigns a dynamic address to the SBC. SBC can then become "lost" all attempts to reach it over IP fail, however it's system led is still flashing indicating main cooperative loop is still active (We flash LED in main cooperative loop, not an interrupt).

Are these know issues with older libraries? Anywhere specific to check for a bug or a work around?

Which brings me to my 3rd question as a short term solution for some of these issues may be to force a reboot on hang:
3) Is there some example code for the hardware watchdog feature? and what is the maximum length of time that can be configured for the watchdog before a board reset (we probably want to use 1-10 seconds) ?

Many thanks.

Webserver Firmware / Re: software timer interrupt
« on: July 18, 2014, 05:17:51 AM »
Hi, when writing embedded code, you must always take care what functions you call from an interrupt ISR. Best is to keep your ISR code as short as possible, and not call any functions from it. If you have to call functions from within an ISR, special care must be taken that they are thread safe. The TickGet() function should not be called from within an ISR. Is there a work around you could use? Could you possibly post your ISR code.

I have stopped using the TickGet(), as it wasn't critical to my code (at this time). However I must use adcGetChanMv(ADC_CH_X1) and  pwm4SetPercent() as part of the PID loop. I've had no problems with them to date, but can you confirm if they are ok to use in the interrupt?

Webserver Firmware / Re: software timer interrupt
« on: July 11, 2014, 07:03:50 AM »
Thank you. On a related note I was debugging my interrupt routine to detrimne/prove how regular its timing it.

I found that calls to "TickGet()" in the interrupt routine (to fetch the system timer for reference) will cause the SBC to "hang" after 1-5 minutes.

Is this a known issue?

Webserver Firmware / Re: software timer interrupt
« on: July 10, 2014, 06:00:00 AM »
Hi, I will get back to you in detail tomorrow when I am back in the office. There are plenty of free timers. I will send you the sample code for implementing a timer ISR.

Thank you. I've made some partial progress. I found some microchip documentation for the PIC and got the following code working:

This initializes the timer
Code: [Select]
        T2CON = 0x00; //Stops the Timer2 and reset control reg.
        TMR2 = 0x00; //Clear contents of the timer register
        PR2 = 15625; //? 15625 seems to give me ~1ms interupts ?
        IPC1bits.T2IP = 0x02; //Setup Timer2 interrupt for desired priority level
        // (this example assigns level 1 priority)
        IFS0bits.T2IF = 0; //Clear the Timer2 interrupt status flag
        IEC0bits.T2IE = 1; //Enable Timer2 interrupts
        //T2CONbits.TGATE = 1; //Set up Timer2 for operation in Gated
        //Time Accumulation mode
        T2CONbits.TON = 1; //Start Timer2

This is my PID code (some counters for debugging only so far):
Code: [Select]
void __attribute__((__interrupt__, __shadow__)) _T2Interrupt (void)
    PID_Counter++;  //PRH increment counter, this is unsigned so just let it wrap around
    IFS0bits.T2IF = 0;    //Clear interrupt status bit Timer2

I'm not sure why (by trial an error) that 
Code: [Select]
PR2 = 15625; gives me ~1ms interrupts so I'd like to learn a bit more about setting up the timing parameters.

Next up the ADC read and PWM set....

Webserver Firmware / software timer interrupt
« on: July 10, 2014, 05:24:57 AM »
I'm using multiple SBC66EC with heavily modified webproject firmware. We now have a requirement for a high speed PID loop (1ms or better cycle time) based on a single analog input and a single PWM output.
I've tried inserting the code in the main loop but the co-operative multitasking of the HTTP and other tasks  make this too slow and to much variation in speed when there is web activity.

I've identified that a software timer interrupt is the way to go for the PID and was using the "ledflash_int/main.c" code as a starting point. Unfortunately timer1 is already used by the Tick.c code for system timer. What other timer may I use in the webproject and is there some example code?

Also what is the quickest way in an interrupt routine to make an ADC read of a particular pin (and how many clock cycles does that take) , and same question or setting a new PWM value for an output pin (cycle count?) - I'd like to get a feel of the latency involved so I can get some correct factors in my PID control.

Many thanks.

Pages: [1]