I am new to this circuit things and still currently learning.

I am trying to build a circuit with a heater and fan that switches to low power mode after 12 hours. Currently I am also trying to learn ASM language so it is taking me some time.

The idea is to use PIC10F200 as a cheap microcontroller clocking and to pull a MOSFET high along with a a resistor to drop the voltage linearly. The blue LED is acting as an indicator and a button can reset the circuit to high. Are IC/AND gates better or do you have any recommendation to build this circuit better?

enter image description here


The following circuit is what I have done thanks to you guys' suggestions.

I have not touch the coding yet but will do soon as I am still learning the ropes.

A voltage regulator is used to power thr PIC10 and per suggestion. A PWM signal will be used along with a MOSFET to modulate power after 12 hrs. After all, I want to built an efficient circuit that does not drop power with linear voltage regulator and AND gates.
My only question left is how many PWM pin does the PIC10 have? I can't find any information on it and wanted it to modulate the heater, fan, and LED. Please let me know my thoughts on this are correct. If not, I am all ears.

A by-pass and diode will be added to the fan:

enter image description here

[EDIT 2]

Hi, I have tried to learn ASM but since I have a little experience in C++ thought might have start with C for a better understanding. PWM1 is meant for LED "breathing" effect and PWM2 is meant to drive the mosfet. Somehow the RA2 is not responding towards if(RA2==1) simple code. close of being done if RA2 is function correctly and writing T0CS as interrupt.

#pragma config FOSC = INTOSC    // Oscillator Selection bits (INTOSC oscillator: CLKIN function disabled)
#pragma config BOREN = OFF      // Brown-out Reset Enable (Brown-out Reset disabled)
#pragma config WDTE = OFF       // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = OFF      // MCLR Pin Function Select bit (MCLR pin function is digital input, MCLR internally tied to VDD)
#pragma config CP = OFF         // Code Protection bit (Program memory code protection is disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable (High-voltage on MCLR/VPP must be used for programming)
#pragma config LPBOR = OFF      // Brown-out Reset Selection bits (BOR disabled)
#pragma config BORV = LO        // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config WRT = OFF        // Flash Memory Self-Write Protection (Write protection off)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>

#define _XTAL_FREQ 8000000
#define SWITCH RA2 

                         Main application
uint16_t pwm1_count = 0 ;
uint16_t pwm1_mode = 0;
uint16_t pwm2_count = 0;
void pwm1_set(uint16_t duty){
     // Set the PWM to the options selected in the PIC10 / PIC12 / PIC16 / PIC18 MCUs.
    // PWM1POL active_hi; PWM1OE enabled; PWM1EN enabled; 
    PWM1CON = 0xC0;   

    PWM1DCH = (uint8_t)(duty & 0x0003 );   
//duty & 0x0003
    PWM1DCL = (uint8_t)(duty >>2 );   
void pwm2_set(void){
     // Set the PWM to the options selected in the PIC10 / PIC12 / PIC16 / PIC18 MCUs.
    // PWM1POL active_hi; PWM1OE enabled; PWM1EN enabled; 
    PWM2CON = 0xC0;   

    // PWM2DCH 196;
    PWM2DCH = 0x3E;  

    // PWM2DCL 65;
    PWM2DCL = 0x00;

void main(void)
    LATA = 0x00 ;

TRISA = 0x0C; ///setting RA2 as input pin 
PORTA = 0x00;
ANSELA = 0x00; 

/////Setting T2CS
T2CON = 0 ;
T2CONbits.TOUTPS = 0 ;
T2CONbits.T2CKPS = 0 ;
PR2 = 19 ;
T2CONbits.TMR2ON = 1;

RA0 = 1 ;
RA1 = 1 ;
    // initialize the device
    while (1)
        if (SWITCH == 1){
        RA0 == 0;
 End of File
  • \$\begingroup\$ trying to learn ASM language - this is nice to have, but the assembly for this specific mcu won't help you much when working with other hardware. Better learn C and use it to program your micros. \$\endgroup\$
    – Eugene Sh.
    Oct 4, 2021 at 16:42
  • \$\begingroup\$ alright. i am still trying to understand ASM and C. some said ASM can better the understanding of the microcontroller and in some application faster than C. which program is more versatile or "future-proof" because i know a little C++ and python but heard it was not recommended for a small microcontroller like this \$\endgroup\$
    – Jones
    Oct 4, 2021 at 17:36
  • \$\begingroup\$ Your Mosfet doesn't switch anything in that circuit diagram. How could it modify the power consumption? \$\endgroup\$
    – Ariser
    Oct 4, 2021 at 18:31
  • \$\begingroup\$ i havn't completed it. was also asking if there is a better way then resistor dropping voltage along with Mosfet when its complete \$\endgroup\$
    – Jones
    Oct 5, 2021 at 1:13

2 Answers 2


PIC10F200 seems a reasonable processor to introduce programming. It has most of the basics, and no extra modules that require careful setup. It does lack interrupts, which this simple application doesn't need.

For this timing application, the 4 MHz internal RC oscillator may lack accuracy that a crystal oscillator would improve.

A resistive divider to take 24V down to 5V to power the microcontroller is very dangerous. Current requirements of the microcontroller will vary, since LED current must come from this source. While the MOSfet gate requires minimal current, charging it quickly does require a spurt of current, which again comes from the VDD supply.

Use some kind of regulator - perhaps a 78L05 would be appropriate. Also add a bypass capacitor directly from VDD to VSS.

The GP0 I/O pin can be freed-up for any other use by setting not_MCLR to be internal. Now it becomes GP3.an input-only pin that would be excellent to use as the pushbutton input (instead of using GP0).

You can run afoul of the watchdog timer - the CONFIG word often keeps it enabled by default. If your main-loop doesn't include a CLRWDT instruction, the watchdog timer will eventually cause a reset, destroying the 12-hour countdown timer. I'd likely set the CONFIG word to disable the watchdog.

A PDIP version of PIC10F200 can be programmed externally, then transferred to a socket in your application circuit.

However, a 6-pin SOT-23 or 8-pin DFN package will require in-circuit programming. Your programmer will want to drive the GP3/not_MCLR/VPP pin with programming pulses, which other parts of your circuit may not tolerate. If you were to make this pin GP3 with the CONFIG word, the push-switch should be left open-circuit while programming. Also required for programming is GP0/ICSPDAT and GP1/ICSPCLK pins during programming. Since the blue LED is connected to GP1, it may light-up during programming - the programmer will likely tolerate the 1k series resistor.


Added code fragment below that illustrates how PIC 10F320 could use its TMR0 to count time, in a 24-bit counter. TMR0 is set up with its pre-scaler so that it overflows about 30 times per second. It is assumed that the 10F320 is being clocked at the default 8 MHz. The interrupt routine simply increments a 24-bit counter in RAM, which has been reset to zero shortly after power-up.

The interrupt routine is triggered by a TMR0 overflow. TMR0 should be the only source that is allowed to cause an interrupt, since no other interrupt flags are tested for activity.

In the main loop where pushbuttons I/O are tested, and LEDs are driven on/off, you'd check the 24-bit counter (time24) to see if it has incremented past the 10 hour setpoint, then do.whatever you wish.

;example TMR0 interrupt routine (MPASM)
;assume default 8 MHz FOSC internal processor clock
;TMR0 overflow triggers interrupt 30.52 interrupts each second.
;TMR0 interrupt routine increments a 24-bit counter

#include p10f320.inc    ;PIC 10F320 is the target Microchip processor

    ;TMR0 initialize code put somewhere into program memory after a hard reset, but
    ;put before main loop:
     cblock 0x40            ;RAM space for variables used by interrupts
                            ;and for the 24-bit counter (to measure timespan)
            W_TEMP, STATUS_TEMP
            time24:3        ;3-bytes counter
        ORG 0               ;reset vector after MCLR has been pulled low, or upon powerup
        goto init           ;initialize all the peripherals: TMR0, PWM, etc
        ORG 04              ;this is interrupt address
    ;TMR0 interrupt service routine follows. If TMR0 has been set up
    ;properly, this interrupt routine runs 30.52 times-per-second
        movwf W_TEMP        ;preserve W temporarily
        swapf STATUS,W      ;preserve status, flags
        movwf STATUS_TEMP
        bcf INTCON,TMR0IF   ;reset TMR0_overflow flag that got us here
        incf time24+0,f     ;increment 24-bit timer (30.52 Hz) least sig.
        btfsc STATUS,Z      ;did 1st byte overflow?
        incf time24+1,f     ;yes, so increment 2nd byte
        btfsc STATUS,Z      ;did 2nd byte overflow?
        incf time24+2,f     ;yes, so increment 3rd byte, most significant
        swapf STATUS_TEMP,W ;restore status, flags
        movwf STATUS
        swapf W_TEMP,f      ;restore W...
        swapf W_TEMP,W
        retfie              ;all done, return to main loop
        bcf OPTION_REG,T0CS ;FOSC/4 is TMR0 prescale clk source
        bcf OPTION_REG,PSA  ;TMR0's clock is routed thru prescaler
    ; from reset, prescaler's default divide is 1:256
    ; least significant 3 bits of OPTION_REG are 111
        clrf TMR0           ;start off with TMR0 count of 0
        bsf INTCON,TMR0IE   ;enable TMR0 interrupt
        bcf INTCON,TMR0IF   ;reset a pending interrupt
        clrf time24+0       ;reset 24-bit counter to zero
        clrf time24+1
        clrf time24+2
        bsf INTCON,GIE      ;only TMR0 should cause an interrupt
    ; add code here to set up I/O pins for input/output (pushbutton, LED)
    ; add code here to set up PWM as well
    ; then proceed to main loop or on to further initialization code
        ;here, you'd add code to compare the 3-byte incrementing
        ; counter (time24) against a 10 hour constant. You'd also check
        ;for activity on the GPIO pin connected to pushbutton
  • \$\begingroup\$ ok thank you ill get update this circuit as soon as possible. Also to my understanding the deviation of the timer in PIC10 is around 1% which should be acceptable if absolute accuracy is not what i am looking for? \$\endgroup\$
    – Jones
    Oct 4, 2021 at 17:33
  • \$\begingroup\$ Yes, one or 2 percent. Data sheet cautions that the factory-set adjustment to oscillator frequency perhaps is erased during re-programming. You might take care to preserve this instruction located at the very end of FLASH memory. Then movwf the value sitting in W into the OSCCAL RAM location 05 - it should be the very first instruction in your program. Otherwise, oscillating frequency may have wider tolerance. \$\endgroup\$
    – glen_geek
    Oct 4, 2021 at 18:00
  • \$\begingroup\$ hi glen_geek, i have been trying to code on MPLAB IDE and apparently the 64 bit version has took off the original library. do you have any recommendation on where i can learn the ASM \$\endgroup\$
    – Jones
    Oct 6, 2021 at 18:02
  • \$\begingroup\$ MPLAB IDE or MPLAB X IDE? The last version of MPLAB IDE was v8.92 (which I still use). It has complete ASM support for 10F200. It also has a simulator that is really excellent for learning ASM coding. Not so useful for more recently-released processors. BTW: 10F200 has no PWM module - you'd have to do this with ASM code...awkward, but could be done. \$\endgroup\$
    – glen_geek
    Oct 6, 2021 at 18:19
  • \$\begingroup\$ MPLAB X IDE 5.35 using mpasm complier. was using 5.50 but apparently they don't have mpasm anymore and since most of the tutorial is on mpasm and i am not proficient enough to translate it that well, I switched. What kind of tool do you usually use? like a pickit tool that can directly interface with the microcontroller on a breadboard? I only have a universal programmer and want to know what a professional like you use normally and think the most of it. Also, though it doesn't have PWM module but i can just write a code to command it to turn on and off in a certain interval right? \$\endgroup\$
    – Jones
    Oct 7, 2021 at 20:04

If you haven't already, get a PIC10F, compatible programmer, and/or dev board and try it with LEDs first. If you can get it to do what you want with LEDs, then it's straightforward to switch a (N-Channel Enhancement-mode) MOSFET instead.

Note R4,5 appear to be a crude 5V supply. Can't power a PIC from a voltage divider; get a real 5V regulator like LM7805 or similar. The moment you try to switch that MOSFET, it's going to draw too much power from a resistor divider and "brown-out" or drop below operating voltage range.

Also note, the motor should have an anti-parallel / free-wheeling / flyback diode across it, and possibly some bypass capacitors. The MCU has it's own bypass cap requirements, don't forget them.

  • \$\begingroup\$ Ok thank you very much ill go and input an LM 7805 and a schottky diode. however, does it make sense to switch to low power mode with a MOSFET along with an additional resistor to drop the voltage? \$\endgroup\$
    – Jones
    Oct 4, 2021 at 17:08
  • \$\begingroup\$ A resistor will just dissipate power as heat. So your circuit board would get hot while the heater cooled some. Consider PWM or pulse-width-modulation for the heater drive. This is where the MOSFET is turned on and off rapidly, and the duty cycle (what percentage of time it's "on") determines how hot it will get. \$\endgroup\$
    – rdtsc
    Oct 4, 2021 at 17:21
  • \$\begingroup\$ ok got it. i will update this as soon as possible \$\endgroup\$
    – Jones
    Oct 4, 2021 at 17:33
  • \$\begingroup\$ hi, i have updated as you recommended. please let me know if the circuit was correctly presented with efficiency expected. \$\endgroup\$
    – Jones
    Oct 5, 2021 at 2:12
  • \$\begingroup\$ Looks better; remember the diode across the fan (in "reverse"). That's to prevent a negative-going voltage spike when the power is removed. Research inductor kickback for an idea of why this is needed. \$\endgroup\$
    – rdtsc
    Oct 5, 2021 at 16:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.