PIC driven fan repair - Page 1
Forum section: electronics / projects

author: StAngus
author_rank: Contributor
timestamp: February 23, 2023, 10:14:33 pm
content: Hi fellow forum dwellers,this is my first post on this forum, as I usually don't do projects that go over my head, but in this case, I might be a bit stubborn.I bought a car seat with some fans for the summer. Shouldn't be hard to drive them without the original car, I thought.Both are controlled by the "seat heater module" via CAN. As I don't need that module, as it just provides power to the fans, I think I went ahead and put 12V 0,5A directly to the fan.Here is where my trouble began. The fan didn't spin and only drew 0,03A.That got me confused, so I removed one fan from the seat to take a closer look.It's a Fergas Airblaster 61001.Greetings to SwedenSo I drilled out the rivets, to get to the PCB, as shown in the picture, to figure out why it won't spin.To this point I have never reverse engineered anything, so be kind with me.I traced out what I could find.Red is positive, white is negative, blue is the signal from the hall sensor and green are the outputs, which drive the mosfets.The coil is getting 11,3V after a 0,7V drop over a diode.Over some transistors and a resistor, the PIC12F675 and the hall sensor are getting 4,9V.When applying 5V to the Mosfet, it moves a bit. So everything points to a dead PIC.So here is where I'm now. Sure I could just buy two new fans, but they're expensive and I'm not sure at this point if I did something wrong here. 2 dead fans seems a bit unlikely to me.I don't now anything about PIC programming, except writing an HEXfile to one. So I have a suitable programmer, if I have to exchange the PIC.Also I asked the manufacturer for details, and got this:12 VDC5400 RPM0,26ANothing special for a fan.My question now:Did I do anything wrong?What does the ground connection on pin 6 do? could it be a signal?Is it possible to write a simple program myself and replace the PIC?I'm thinking like: Hall sensor high = mosfet 1, sensor low = mosfet 2I hope someone can push me in the right direction here .Wish you all the best.

author: cantata.tech
author_rank: Regular Contributor
timestamp: February 23, 2023, 10:27:39 pm
content: Quote from: StAngus on February 23, 2023, 10:14:33 pmMaybe you can post a photo ? Is this your project/upgrade?

author: james_s
author_rank: Super Contributor
timestamp: February 23, 2023, 11:26:48 pm
content: It's impossible to say without at least seeing some pictures. Is it a brushed motor? If so you should be able to bypass all of the electronics and just give it power.

author: StAngus
author_rank: Contributor
timestamp: February 24, 2023, 07:42:30 am
content: Strange, I'm sure I uploaded pictures in my post.Also I'm pretty sure it's a brushless fan.

author: james_s
author_rank: Super Contributor
timestamp: February 24, 2023, 07:48:24 am
content: It's hard to tell what's going on there but it looks like that might be a 2 phase brushless motor similar to the sort used in computer fans. Are those two 3-terminal devices transistors?

author: StAngus
author_rank: Contributor
timestamp: February 24, 2023, 08:16:33 am
content: They are 8n06lt MOSFETs. The drain is connected to the coil and gate to the PIC.

author: jpanhalt
author_rank: Super Contributor
timestamp: February 24, 2023, 10:23:04 am
content: Quote from: StAngus on February 23, 2023, 10:14:33 pmAssuming you applied the 5V to the mosfet gate, and if it is a brushless motor, I am not sure that test points to the PIC as the problem. Do you have any way to 'scope the PIC pins to the mosfet gates? You might also want to test the voltage at pin 4 of the PIC. It should be pulled up to 5V.Secondly, if it is the PIC, it is unlikely you could get the hex file to program a new one.

author: StAngus
author_rank: Contributor
timestamp: February 24, 2023, 12:50:00 pm
content: As I don't have a scope, I tried the peak feature of my multimeter, but to no avail.It just shows 0.Considering the PIC doesn't need to be somehow triggered first, it seems dead to me.Going with that, getting a new PIC isn't the problem.I have a K150 programmer which I used to put hex-files on PIC12C508A.But that's all my experiece on PICs.To create a file, it seems like I need MPLAB IDE and a C code.Is there a reason why Pin 6 is grounded over an 6.1k resistor?

author: jpanhalt
author_rank: Super Contributor
timestamp: February 24, 2023, 03:27:38 pm
content: The newer picture is clearer. I can barely make out the "675." Snippet attached. Pin 1 appears to be upper right. My original post assumed Pin 1 was lower left I could read any thing off it. I don't know why Pin 6 has a resistor to ground, unless it is connected to a gate. Although, PIC pins are supposed to source or sing up to 25mA.My point about programming had nothing to do with the electrical aspects and was referring to the likelihood that the chip's program is probably "protected" and cannot be read without a whole lot of effort. Without that program, you would need to write the code yourself.

author: james_s
author_rank: Super Contributor
timestamp: February 24, 2023, 05:51:57 pm
content: And if the chip is dead, it's unlikely you would be able to extract the code even if it was not protected.Maybe just replace the whole circuit with one from a computer fan?

author: coppercone2
author_rank: Super Contributor
timestamp: February 24, 2023, 10:03:25 pm
content: this gave me an idea for a scientific fan, what if you made a fan controller that is RPM adjustable to single digit with a PIC and the tachyometer feedback, so you can do precision airflow experiments. Like a board that you can adjust with a encoder that control the fan.

author: jpanhalt
author_rank: Super Contributor
timestamp: February 24, 2023, 10:20:37 pm
content: Who would care? More on point, there are real airflow instruments when that is what you want to measure (e.g., biological and chemical safety cabinets). The reason you have a fan in this instance is to control temperature, Thus, there is often temperature feedback.

author: coppercone2
author_rank: Super Contributor
timestamp: February 24, 2023, 10:43:49 pm
content: idk its like asking why is there a hand soldering iron adjustable to 0.1 degree C, anyway its a easy project. instead of another constant current load

author: StAngus
author_rank: Contributor
timestamp: February 25, 2023, 10:12:23 am
content: I already checked the PCBs of some PC fans I have around, but they won't fit, as the part in middle is rather thick.After Dave's video about the Chat GPT coding, I had to try it myself for this, but I didn't get a code, just instruction on how the program should opperate. I mean, it's a start, as I have no experience in writing actual code myself, yet.If that works, maybe I can try hooking up an rotary enconder to the upopulated pins of the PIC. Using a latch I could even use it's switch to turn on and off the fans.For reading out the chip: It didn't even come to my mind to try that. If I get it out in one piece, I'll try it jsut for the heck of it.

author: mikerj
author_rank: Super Contributor
timestamp: February 25, 2023, 11:38:56 am
content: Quote from: StAngus on February 24, 2023, 12:50:00 pmPin 6 is a comparator input on this PIC, are you certain the trace doesn't connect to anything else where it goes under the broken black plastic?

author: jpanhalt
author_rank: Super Contributor
timestamp: February 25, 2023, 12:05:08 pm
content: Writing code to switch on/off such a motor would not be hard if you know which pins do what, i.e., the I/O's for every pin. There are only 6 and perhaps only 4 or 5 that you don't already know. Pin 4 (!MCLR)can be used as an input, but based on my brief look at the PCB, I don't think it is. If there is an external control with a bus, e.g., CAN bus, then it would be more difficult if you have to learn how to code at the same time.The problem is, you won't know until after you do it. PIC's are pretty durable, but they can be destroyed by electrical malfunction, like reverse voltage or prolonged excessive voltage. IMHO, there is a significant probability that replacing that PIC with a perfectly programmed new one may not work either. Maybe something else in the circuit is causing the failure or caused the PIC to fail.I did not see any programming pads/pins on thar PCB. For that chip, a minimum of 3 pins plus VCC and GND are needed. A typical interface will have 5 pins. The programming pins are Pins 4, 6, & 7. Pin 6 does not appear to be connected to anything on your board. Therefore, unless you can find a programming port, you will need to remove the chip to program it, then reverse the process to see if your program works. But, even a perfectly programmed chip may not work or less likely, may be destroyed.I would remove the known good chip and test it in the defective board. That is a little extra work, and it carries the slight risk it may be destroyed too, but it could also save you a lot of work from going down a dead end.

author: StAngus
author_rank: Contributor
timestamp: February 25, 2023, 12:39:23 pm
content: Quote from: mikerj on February 25, 2023, 11:38:56 amYou're right, it's also connected to the capacitor C6 and and 20k resistor next to the VCC of the hall sensor.

author: StAngus
author_rank: Contributor
timestamp: February 25, 2023, 01:09:56 pm
content: Quote from: jpanhalt on February 25, 2023, 12:05:08 pmAs both fans I have won't spin, I don't have any working reference.I started learning about PICs an came to the conclusion that pin 2 and 3 shopuld be opperated as GP5 and 4. Pin 4 is connected to the hall sensor, therefore isn't used for MCLR. If MCLR is disabled, it can be used as GP3 but only as input, so it's likely that.Soldering parts in and out is more my cup of tea, than programming.I tested alls components and everything seems fine, expect the missing outputs on GP5 and 4.Getting the chip out and try to read it will unfortunately take some time, as I left my soldering equipment at work and I won't be there till thursday.Till then, I'll buy some PICs a SMD breakout board and try to learn some programming.

author: StAngus
author_rank: Contributor
timestamp: March 02, 2023, 05:24:27 pm
content: Update on the project:I tried ChatGPT again and got a codeCode:#define _XTAL_FREQ 4000000#define MOSFET1 GP5#define MOSFET2 GP4#define HALL GP3void main(void) {ANSEL = 0x00;ADCON0 = 0x00;CMCON = 0x007;VRCON = 0x00;TRISIO = 0x008; //GP3 input, other outputGPIO = 0x00;while(1){// Read the output of the Hall effect sensorint hall_value = HALL;// Use a speed control algorithm to adjust the motor speed to the desired 5000rpm// ...// Determine which phase to activate based on the hall sensor valueswitch (hall_value) {case 0:// Phase 1: activate phase 1 and deactivate phase 2MOSFET1 = 1;MOSFET2 = 0;break;case 1:// Phase 2: activate phase 1 and phase 2MOSFET1 = 1;MOSFET2 = 1;break;case 2:// Phase 3: deactivate phase 1 and activate phase 2MOSFET1 = 0;MOSFET2 = 1;break;case 3:// Phase 4: deactivate phase 2 and activate phase 1MOSFET1 = 1;MOSFET2 = 0;break;}// Delay for 11ms__delay_ms(11);}return;}I compiled it using MPLAB, got the HEX-File and put it on a fresh PIC12F675 and soldered it in.Well it runs, but poorly, with 1800-2100 RPM (instead aof 5600).I also tried to read the old chip, but it gave out all zeroes. Maybe because it's broken or read protected.Anyway, I got more than before, so I will go on and optimise the code.

author: james_s
author_rank: Super Contributor
timestamp: March 02, 2023, 06:37:28 pm
content: That's actually really impressive, I'm shocked that ChatGPT gave you code that worked at all.

author: StAngus
author_rank: Contributor
timestamp: March 02, 2023, 07:13:57 pm
content: Quote from: james_s on March 02, 2023, 06:37:28 pmMe too, glad Dave made that video, else I wouldn't even have tried that route.Next problem, is my programmer though. I bought it very cheap and I got very cheap. It now works less, than the fan. Stupid K150, should have gone directly for PicKit 3.

author: james_s
author_rank: Super Contributor
timestamp: March 02, 2023, 07:21:23 pm
content: Even a cheap programmer should work, I use a TL866 to program PICs.

author: SuzyC
author_rank: Frequent Contributor
timestamp: March 03, 2023, 03:50:44 pm
content: __delay_ms(11);The above is the existing delay between drive phase changes in your fan speed code.Halve the delay to maybe get twice the fan speed?

author: StAngus
author_rank: Contributor
timestamp: March 03, 2023, 04:13:22 pm
content: Quote from: SuzyC on March 03, 2023, 03:50:44 pmThat's my next step, when I get my new programmer. Ordered a PicKit2 yesterday.I followed the only reasonable forumpost about the K150 I could find:Quote

author: StAngus
author_rank: Contributor
timestamp: March 10, 2023, 11:57:27 am
content: Small update:I got a new programmer and at least that isn't an issue anymore.After setting the delay from 11 to 5ms the fan spins a bit faster, but draws way too much current.Also still doesn't start spinning on its own, but that was expected.

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: March 10, 2023, 12:16:45 pm
content: It looks like there is only a single input for the Hall sensor. How are you getting four states?

author: StAngus
author_rank: Contributor
timestamp: March 12, 2023, 06:19:37 pm
content: Quote from: Ground_Loop on March 10, 2023, 12:16:45 pmIt's just what ChatGPT gave me to work with. I thought it jsut counts the inputs?There is only one hall sensor.But there are some good news, I got the heat elements and the electrical seat-adjustment running.

author: StAngus
author_rank: Contributor
timestamp: March 16, 2023, 04:49:15 pm
content: I deleted the preivous update, because I found a problem with the code I wrote.So the new code is:Code:#include "Includes.h"// Define PWM pin#define MOSFET1GP4#define MOSFET2GP5void interrupt ISR(void){if(GP3) //If HALL is triggered{if(T0IF) //If Timer0 Interrupt{if(MOSFET1)// if MOSFET1 is high{MOSFET1 = 0;TMR0 = PWM;}else// if MOSFET1 is low{MOSFET1 = 1;TMR0 = 255 - PWM;}T0IF = 0; // Clear the interrupt__delay_us(750);MOSFET1 = 0; // Deactivate MOSFET1}}if (GP3 == 0){if(T0IF) //If Timer0 Interrupt{if(MOSFET2)// if MOSFET2 is high{MOSFET2 = 0;TMR0 = PWM;}else// if MOSFET2 is low{MOSFET2 = 1;TMR0 = 255 - PWM;}}T0IF = 0; // Clear the interrupt__delay_us(750);MOSFET2 = 0; // Deactivate MOSFET2}}PWM is changeable in main, this is just the interrupt.The fan is actually spinning better now, but still hits current spikes.Here is a small video of the fan running this program without the 10 second delay and PWM set to 200.https://youtu.be/Zp5g3TAAXDAThe clicking sound is just over current protection of the power supply.Edit: updated code. Spins now with about 10.000rpm but doesn't start on it's own.

author: StAngus
author_rank: Contributor
timestamp: March 17, 2023, 06:47:00 pm
content: I got the timing right, so the fan is spinning correctly now and the power supply doesn't go nuts anymore.BUT it doesn't start spinning on its own now.I tried to write a simple code to give it a nod in the right direction, but if I do this, everything stops working.Code:void main(){ANSEL = 0x00; // Set ports as digital I/O, not analog inputADCON0 = 0x00;// Shut off the A/D ConverterCMCON = 0x07;// Shut off the ComparatorVRCON = 0x00;// Shut off the Voltage ReferenceTRISIO = 0x08; // GP3 input, rest all outputGPIO = 0x00; // Make all pins 0InitPWM();// Initialize PWMPWM = 180;// 50% duty cyclewhile(1){}}This is the main.c , if I put a function like "void start(void)" with some code after that, it only does that and nothing else. I tried return at the end, but to no avail.I searched some stuff on google of course, but it's hard for me to differentiate between C and C++ and even if it is C, some things just don't work. I think it's because of the rather old HI-Tech compiler I'm using.

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: March 18, 2023, 02:51:29 am
content: Put your start code before the while(1) statement in main without making it a function.

author: StAngus
author_rank: Contributor
timestamp: March 18, 2023, 06:43:25 am
content: Thank you so much, that was the error. Now only some optimization left to do.But first some breakfast and coffee.

author: StAngus
author_rank: Contributor
timestamp: March 18, 2023, 08:57:15 pm
content: Ok, I'm done now.After trying for hours I just can't get the RPM above 3600. Maybe it's just the limitation of the motor, even if it should be 5400 @ 12V.Maybe I'll need a more advanced algorithm, but that's just out of my league.My final code:ISR.cCode:void interrupt ISR(void){if(GP3) //If HALL is triggered{if(T0IF) //If Timer0 Interrupt{if(MOSFET1)// if MOSFET1 is high{MOSFET1 = 0;TMR0 = PWM;}else// if MOSFET1 is low{MOSFET1 = 1;TMR0 = 255 - PWM;}T0IF = 0; // Clear the interrupt__delay_us(fandelay);MOSFET1 = 0; // Deactivate MOSFET1}}if (GP3 == 0){if(T0IF) //If Timer0 Interrupt{if(MOSFET2)// if MOSFET2 is high{MOSFET2 = 0;TMR0 = PWM;}else// if MOSFET2 is low{MOSFET2 = 1;TMR0 = 255 - PWM;}}T0IF = 0; // Clear the interrupt__delay_us(fandelay);MOSFET2 = 0; // Deactivate MOSFET2}}Include.hCode:#ifndef __INCLUDES_H#define __INCLUDES_H#define MOSFET1GP5#define MOSFET2GP4#include <htc.h>#define _XTAL_FREQ 4000000#define fandelay 600#include "PWM.h"#include "ISR.h"#endifmain.cCode:#include "Includes.h"// Config word__CONFIG(FOSC_INTRCIO & WDTE_OFF & PWRTE_ON & MCLRE_OFF & BOREN_ON & CP_OFF & CPD_OFF);// Main functionvoid main(){ANSEL = 0x00; // Set ports as digital I/O, not analog inputADCON0 = 0x00;// Shut off the A/D ConverterCMCON = 0x07;// Shut off the ComparatorVRCON = 0x00;// Shut off the Voltage ReferenceTRISIO = 0x08; // GP3 input, rest all outputGPIO = 0x00; // Make all pins 0MOSFET2 = 1;__delay_ms(50);MOSFET2 = 0;MOSFET1 = 1;__delay_ms(50);MOSFET1 = 0;__delay_ms(200);MOSFET2 = 1;__delay_ms(50);MOSFET2 = 0;MOSFET1 = 1;__delay_ms(50);MOSFET1 = 0;InitPWM();// Initialize PWM// PWM=0 means 0% duty cycle and// PWM=255 means 100% duty cyclePWM = 50;// 50% duty cyclewhile(1){}}The fan draws about 350mA whitch exeeds the 260mA in the specification, but that's good enough for Australia, not Austria.Shout out sohttps://saeedsolutions.blogspot.comfor providing a base code to work on.

author: Ground_Loop
author_rank: Frequent Contributor
timestamp: March 19, 2023, 12:52:53 am
content: I would try to reduce the pulse width to the FETs. You’ll need to use a timer.

author: StAngus
author_rank: Contributor
timestamp: March 19, 2023, 06:42:07 am
content: I appreciate your input, but there is no way I could implement that on my own. I don't even know why it only works with the delays at that place.It's like the old PC in the corner of the office, nobody knows what it is doing, but without it nothing works.Maybe if I had an oscilloscope I could visualize what is happening in the timer 0 section, but I don't have one.Feel free to post a code I could test, but my mental capacity for this project is gone.

author: NiHaoMike
author_rank: Super Contributor
timestamp: March 19, 2023, 03:38:16 pm
content: Quote from: StAngus on March 18, 2023, 08:57:15 pmSounds like it uses field weakening at high RPM. Also note that automotive "12V" is actually more like 14.4V.

author: StAngus
author_rank: Contributor
timestamp: March 29, 2023, 09:03:16 pm
content: Ok, just ordered a new fan, as I didn't want to rip the other one apart too. The metal halfs a riveted together and the PCB is enclosed plastic,. which you have to break apart.Quess what: Doesn't spin and draws 3mA just like the ones I already got.So it looks like it really needs something to be activated.I broke open the controll modul to see, how the fan is activated.It shares a common ground with the connector for the heating elemen. The positiv comes from a VN750S.From my understanding, it is just a fancy MOSFET, so the board computer can switch the fan on and off via the can bus.What am I missing here?I tried with some higher voltage, but to no avail.

author: james_s
author_rank: Super Contributor
timestamp: March 29, 2023, 10:38:56 pm
content: Have you tried feeding it a PWM signal?The easiest solution here would be finding someone that has the kind of car the fan came from and scoping the signal. Maybe you can find a forum dedicated to maintaining such cars?

author: StAngus
author_rank: Contributor
timestamp: March 30, 2023, 04:18:13 pm
content: Yeah, PWM; was the second thing I tried. Looking at the PCB I don't know how that would change things.If the VN750S to create a PWM signal, only Vcc of the PIC would get it.I tried everything on the volvo side first, but ther just isn't any details to get and I wouldn't bother anyone with an Volvo V70III to get a portable scope underneath their carseat.In the end, it's just a fan and not rocket science. Every extra step would cost more money, and no manufacture like that.There are LIN controlled fans, but they have 3 wires.Also, I still don't understand what Pin6 does. It's connected to ground via a 6,1k resistor.

author: StAngus
author_rank: Contributor
timestamp: March 31, 2023, 11:19:24 am
content: QuoteI was blind here. It also is connected to the input voltage over a 20k resistor. So it it is possible that the V750S is creating some kind of signal

author: james_s
author_rank: Super Contributor
timestamp: March 31, 2023, 04:51:26 pm
content: What you describe sounds like a voltage divider that takes a sample of the input voltage and feeds it to that pin.