Dangerous Prototypes

Dangerous Prototypes => USB Infrared Toy => Topic started by: liyin on August 18, 2010, 09:04:26 pm

Title: IR Toy Temperature
Post by: liyin on August 18, 2010, 09:04:26 pm
I noticed the PIC gets warmer when the IR Toy is enclosed, I thought that circuits this small didn't warm up like this.

Will see what I get with an IR thermometer.
Title: Re: IR Toy Temperature
Post by: ian on August 18, 2010, 09:14:00 pm
It's running at 12MIPs/48mhz, it will get a bit warm. That PIC also has an internal 3.3volt regulator for the USB, which will get warm. So will the pull-up resistors, and the LED.
Title: Re: IR Toy Temperature
Post by: rsdio on August 18, 2010, 09:39:28 pm
The USB section must run at 48 MHz, but it might be possible to slow down the CPU a great deal to save current.  An unfortunate side effect of slowing the CPU is that peripherals are slower, too, but I think the IR frequencies are already way slower than 48 MHz, so it might work well to run the CPU at a fraction of the maximum.

Of course, slowing the CPU and peripheral clock will not reduce the current for the LED or internal pull-up resistors.  But reducing the CPU speed could make the regulator run cooler since less current would be used.

P.S. if there is a tight spin loop in the firmware, then a sleep instruction might reduce power, except that I've found USB will not work in conjunction with PIC sleep - I think the features are mutually exclusive.
Title: Re: IR Toy Temperature
Post by: liyin on August 18, 2010, 09:56:33 pm
If things work the same, I don't mind a dimmer LED. Is summer and the temperatures are kinda hot right now.

Maybe it could be made a selectable thing.
Title: Re: IR Toy Temperature
Post by: rsdio on August 19, 2010, 03:22:04 am
[quote author="liyin"]
If things work the same, I don't mind a dimmer LED. Is summer and the temperatures are kinda hot right now.

Maybe it could be made a selectable thing.
[/quote]I don't think the LED is the biggest heater.  If it is, the bulk of the heat should be radiated from the resistor, so check the temperature there for confirmation.  If the resistor is not hot, then I doubt you could make much of a difference by making the LED dimmer.  If it is hot, then you could try a high-efficiency LED so that you could reduce the current even further, and thereby reduce the heat.

The peak DC current on the LED is set by the resistor, so it would be hard to make the maximum selectable, except for users with a soldering iron.  The firmware could pulse the LED to dim it, but that seems like a waste of CPU cycles unless the heat is significant (and I doubt it is).  If the LED were attached to RB3 instead of RA0, then it could be pulsed automatically by the PWM/CCP2 output, but that peripheral is probably already in use for timing.

I'll have to check my v1 for heat.  We're getting record temperatures here, too.
Title: Re: IR Toy Temperature
Post by: liyin on August 19, 2010, 04:21:09 am
I haven't detected any heat from the LED. I misread your post and referred to a dimmer LED as a side-effect of slowing the MCU.

I felt some heat under the board, but mostly above the MCU.
Title: Re: IR Toy Temperature
Post by: rsdio on August 19, 2010, 06:46:02 am
Ok.  The LED will not get any dimmer when you slow the CPU, neither the visible nor infrared LED.

If you wanted a fun project, grab the firmware sources, drop the CPU clock, recalculate all of the peripheral dividers to produce the same working frequencies, and recompile.  It would be interesting to see how much cooler it runs.

Another interesting test would be to measure the current drawn over USB.  All of my PIC designs have a jumper on USB power so I can measure the current, but I suppose a USB breakout cable would allow the same thing.
Title: Re: IR Toy Temperature
Post by: liyin on August 24, 2010, 08:06:01 pm
How do I turn off PLL and set CPUDIV (10) => (11)?
Title: Re: IR Toy Temperature
Post by: ian on August 24, 2010, 10:07:52 pm
PLL is a config bit that can't be changed from code. You might be able to change the CPU divider though, it will be in the osc section of the datasheet. If you change the frequency the USB will probably not work correctly, it requires a fixed divider to create a 96mhz frequency with teh PLL. I think it it /2 or /5, I forget.
Title: Re: IR Toy Temperature
Post by: liyin on August 24, 2010, 10:45:29 pm
I thought the "Oscillator Configuration Options For USB Operation" table would give configuration settings that work with USB.

Under 20MHz input oscillator there are settings with the PLL and settings without the PLL (HSPLL vs HS, ECPLL vs EC).

So it seems you can disable the PLL by switching the "Clock Mode".

If that's not the case, then I understand nothing about PIC's. And will hate Microchip 4ever.    :p
Title: Re: IR Toy Temperature
Post by: rsdio on August 24, 2010, 11:08:45 pm
Look at the diagram on page 24 of the data sheet.  The PLL must be operating at 96 MHz for USB to operate.  However, the CPU and Peripherals can get their clock from two sources.  FOSC3:FOSC0 chooses between the PLL Postscaler and the Oscillator Postscaler.  The PLL Postscaler offers 48 MHz, 32 MHz, 24 MHz, and 16 MHz.  The Oscillator Postscaler depends upon your crystal frequency.  Since the USB Infrared Toy has a 20 MHz crystal, that gives the option of 20 MHz, 10 MHz, 6.67 MHz, and 5 MHz.

Unfortunately, CPUDIV and FOSC3:FOSC0 are part of Configuration Registers which can only be changed by a PIC programmer.

But if you read all of Chapter 2 on the Oscillator, you learn that Timer1 or the Internal Oscillator Block can be selected at run time for reduced CPU speeds.  See section 2.4

Keep in mind that if you change the frequency in CPUDIV, then all of the peripherals (besides USB) will need to have their clock settings recalculated.  i.e. Your timer prescalers and counter values will have to change in order to maintain the same final frequency.
Title: Re: IR Toy Temperature
Post by: liyin on August 24, 2010, 11:31:58 pm
Quote
2.2.1 OSCILLATOR MODES AND USB OPERATION

Because of the unique requirements of the USB module, a different approach to clock operation is necessary. In
previous PIC® devices, all core and peripheral clocks were driven by a single oscillator source; the usual
sources were primary, secondary or the internal oscillator. With PIC18F2455/2550/4455/4550 devices, the
primary oscillator becomes part of the USB module and cannot be associated to any other clock source. Thus,
the USB module must be clocked from the primary clock source; however, the microcontroller core and other
peripherals can be separately clocked from the secondary or internal oscillators
as before.

Because of the timing requirements imposed by USB, an internal clock of either 6 MHz or 48 MHz is required
while the USB module is enabled. Fortunately, the microcontroller and other peripherals are not required
to run at this clock speed when using the primary oscillator.
There are numerous options to achieve the
USB module clock requirement and still provide flexibility for clocking the rest of the device from the primary
oscillator source. These are detailed in  Section 2.3 “Oscillator Settings for USB”.

Quote
2.2.4 PLL FREQUENCY MULTIPLIER

PIC18F2455/2550/4255/4550 devices include a Phase Locked Loop (PLL) circuit. This is provided specifically
for USB applications with lower speed oscillators and can also be used as a microcontroller clock source.

The PLL is enabled in HSPLL, XTPLL, ECPLL and ECPIO Oscillator modes. It is designed to produce a
fixed 96 MHz reference clock from a fixed 4 MHz input. The output can then be divided and used for both the
USB and the microcontroller core clock. Because the PLL has a fixed frequency input and output, there are
eight prescaling options to match the oscillator input frequency to the PLL.

There is also a separate postscaler option for deriving the microcontroller clock from the PLL. This allows the
USB peripheral and microcontroller to use the same oscillator input and still operate at different clock
speeds. In contrast to the postscaler for XT, HS and EC modes, the available options are 1/2, 1/3, 1/4 and 1/6
of the PLL output.

The HSPLL, ECPLL and ECPIO modes make use of the HS mode oscillator for frequencies up to 48 MHz.
The prescaler divides the oscillator input by up to 12 to produce the 4 MHz drive for the PLL. The XTPLL mode
can only use an input frequency of 4 MHz which drives the PLL directly.

Quote
2.2.5.1 Internal Oscillator Modes

When the internal oscillator is used as the microcontroller clock source, one of the other oscillator
modes (External Clock or External Crystal/Resonator) must be used as the USB clock source
. The choice of
the USB clock source is determined by the particular internal oscillator mode.

There are four distinct modes available:
1. INTHS mode: The USB clock is provided by the oscillator in HS mode.
2. INTXT mode: The USB clock is provided by the oscillator in XT mode.
3. INTCKO mode: The USB clock is provided by an external clock input on OSC1/CLKI; the OSC2/
CLKO pin outputs FOSC/4.
4. INTIO mode: The USB clock is provided by an external clock input on OSC1/CLKI; the OSC2/
CLKO pin functions as a digital I/O (RA6).

Quote
2.3 Oscillator Settings for USB

When these devices are used for USB connectivity, they must have either a 6 MHz or 48 MHz clock for
USB operation, depending on whether Low-Speed or Full-Speed mode is being used. This may require some
forethought in selecting an oscillator frequency and programming the device.

The full range of possible oscillator configurations compatible with USB operation is shown in Table 2-3.


2.3.2 RUNNING DIFFERENT USB AND MICROCONTROLLER CLOCKS

The USB module, in either mode, can run asynchronously with respect to the microcontroller core and
other peripherals. This means that applications can use the primary oscillator for the USB clock while the micro-
controller runs from a separate clock source at a lower speed. If it is necessary to run the entire application
from only one clock source, full-speed operation provides a greater selection of microcontroller clock
frequencies.

Legend: All clock frequencies, except 24 MHz, are exclusively associated with full-speed USB operation (USB clock of 48 MHz). Bold is used to highlight clock selections that are compatible with low-speed USB operation (system clock of 24 MHz, USB clock of 6 MHz).

Quote
12.3.1 USING TIMER1 AS A CLOCK SOURCE

The Timer1 oscillator is also available as a clock source in power-managed modes. By setting the clock select
bits, SCS1:SCS0 (OSCCON<1:0>), to ‘01’, the device switches to SEC_RUN mode. Both the CPU and
peripherals are clocked from the Timer1 oscillator. If the IDLEN bit (OSCCON<7>) is cleared and a  SLEEP
instruction is executed, the device enters SEC_IDLE mode. Additional details are available in Section 3.0
“Power-Managed Modes”.

Whenever the Timer1 oscillator is providing the clock source, the Timer1 system clock status flag, T1RUN
(T1CON<6>), is set. This can be used to determine the controller’s current clocking mode. It can also indicate
the clock source being currently used by the Fail-Safe Clock Monitor. If the Clock Monitor is enabled and the
Timer1 oscillator fails while providing the clock, polling the T1RUN bit will indicate whether the clock is being
provided by the Timer1 oscillator or another source.
Title: Re: IR Toy Temperature
Post by: rsdio on August 24, 2010, 11:45:36 pm
Looks like you didn't quite make it to section 2.4, which is your only option without a PIC programmer that can change Configuration Registers.
Title: Re: IR Toy Temperature
Post by: liyin on August 24, 2010, 11:57:14 pm
Still editing and gathering ideas. What do you mean, will a PICkit 2 work?

Now I'm not so sure, last time the IR Toy went dead, I couldn't revive it with the PICkit 2.
 
And what about low-speed USB operation?
Title: Re: IR Toy Temperature
Post by: rsdio on August 25, 2010, 01:07:07 am
[quote author="liyin"]Still editing and gathering ideas. What do you mean, will a PICkit 2 work?[/quote]PICkit 2 would be perfect.  There are other options, too.

Quote
Now I'm not so sure, last time the IR Toy went dead, I couldn't revive it with the PICkit 2.
That doesn't make sense, unless you weren't using it right.  How was that IR Toy revived anyway, if not via some kind of PIC programmer?

Quote
And what about low-speed USB operation?
First of all, you can't change to Low Speed any easier than changing the other Oscillator settings because they're all in the Configuration Settings, so what's the point?  Secondly, CDC may not work properly at Low Speed.  Many USB protocols are confined to one speed or the other, so you would have to rewrite everything, and that includes both the USB IR Toy firmware and the clients (which are all based on CDC).

What you want to do is modify the OSCCON register.
Title: Re: IR Toy Temperature
Post by: liyin on August 25, 2010, 01:32:29 am
I have used the PICkit 2 before with no problems, but it couldn't detect the non-working IR Toy. I explained the experience in the "IR Toy Dead (Again)" thread.

I used a male pin header and hold it in place with one hand (bad contact?). The only way to revive it was to short PGC/PGD using the same pin header.
Title: Re: IR Toy Temperature
Post by: rsdio on August 25, 2010, 01:58:49 am
[quote author="liyin"]
I have used the PICkit 2 before with no problems, but it couldn't detect the non-working IR Toy. I explained the experience in the "IR Toy Dead (Again)" thread.

I used a male pin header and hold it in place with one hand (bad contact?). The only way to revive it was to short PGC/PGD using the same pin header.
[/quote]I have used the PICkit 2 with my USB IR Toy, and it recognized the PIC just fine.  If you're having trouble with a header that is held in place by hand, then I suggest soldering on an ICSP header to avoid these kinds of problems.  There's no good reason why a PICkit 2 would not work with the IR Toy.

By the way, I also have a PIC KIT2 clone from PIC16.com (http://http://www.pic16.com/).  It costs about the same as the Microchip PICkit 2, but it has a cable adaptor for the ICSP which fits better on the tiny IR Toy PCB.  I don't necessarily recommend the product, but I mention it here because it also recognizes the IR Toy PIC just fine.
Title: Re: IR Toy Temperature
Post by: ian on August 25, 2010, 09:39:20 am
You're right, I'm wrong. I forgot the 18F2550 had a separate divider for the CPU clock. As far as I know, it is still impossible to disable PLL without setting the configuration bits with a PIC programmer (burning a new firmware), but you can manipulate the CPU clock divider from user code.

( ! ) Fatal error: Uncaught exception 'Elk_Exception' with message 'Please try again. If you come back to this error screen, report the error to an administrator.' in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
( ! ) Elk_Exception: Please try again. If you come back to this error screen, report the error to an administrator. in /var/www/dangerousprototypes/forum/sources/database/Db-mysql.class.php on line 696
Call Stack
#TimeMemoryFunctionLocation
10.01262120968session_write_close ( )...(null):0
20.01302252544ElkArte\sources\subs\SessionHandler\DatabaseHandler->write( )...(null):0
30.01302253320Database_MySQL->query( ).../DatabaseHandler.php:119
40.05882392040Database_MySQL->error( ).../Db-mysql.class.php:273