PWM for heating car's exterior mirrors


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2012
    Posts
    5

    Default PWM for heating car's exterior mirrors

    Hello!
    At my car, exteriors mirrors heating was done with help of an electronic module, based on a temperature sensor readings. Because that module is broken and too expensive to buy, after some searching on web, I found a schematic which contain a PIC12F675 and a LM35 temperature sensor, used for PWM a fan. Also, I found the necessary code.
    Because I have no experience in PicBasicPro, after several attempts to modify the code, I had to give up and call for help. The code is written approx. 70%, only the main iteration is missing.
    So, please, someone to complete blank spaces on attached file.

    Thank you so much and Merry Christmas to all!

    PWM for heating the mirrors.bas

  2. #2
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Code:
    '   PIC12F675
    '   LM35, temperature sensor
       
       
       ' @device	mclr_off
       
    
        tempSensor con 3            'this is the analog input that the temperature sensor is connected to
        LED var GPIO.2              'LED output
        HEAT var GPIO.5             'Mirror heating output
        
        
        Define	OSCCAL_1K	1	' Calibrate internal oscillator
        
        ' Define ADCIN parameters
        Define	ADC_BITS	10	' Set number of bits in result
        Define	ADC_CLOCK	3	' Set clock source (3=rc)
        Define	ADC_SAMPLEUS	50	' Set sampling time in uS
        
        'define some variable that are needed
        rawTempData	Var	Word	' Create rawTempData to store result
        calculatedTemp var Word ' Calculated temperature
        heatPWMValue var Word    ' The mirrors'heat needed
        heatON var Bit    ' Keeps track of the heat condition (ON or OFF)
        heating con 1           ' value of a heated mirror
        notHeating con 0        ' value of a nonheated mirror
        heatPWMCycleCounter var Word 'keeps track of the number of PWM loops we have done
        heatPWMCounter var Word  'keeps track of the required PWM count
        numberOfPWMCyclesNeeded con 50  'this will cause the temp to be checked around every 1/2 second
        PWMPauseTime con 1      'number of miliseconds to pause between PWM ticks
        
        
        
        ADCON0.7 = 1		' Right justify result
        ANSEL = %00111000	' Set AN3 analog, rest digital
        CMCON = 7		    ' Analog comparators off
        
        'show startup sequence
        GoSub startup
        
    'Get the analog value of the sensor, convert it to celcius and display the results    
    mainloop :   
    	
        ADCIN TempSensor, rawTempData		' Read channel 3 to rawTempData
    
        GoSub CalculateTemperature 'calculate the actual temp
    
        GoSub PWMheatControl  'control the heat based on the current temperature
        
        
    GoTo mainloop		' loop forever
    
    
    'Calculate what the actual temperature is based on the value that was read in    
    CalculateTemperature:
    
        'The analog input has 10 bits or resolution wich means that 0 through 5 volts is
        'converted to a number between 0 and 1023. Each step represents 5V / 1024 = 0.004883
        'This is aproximately .0049 therefore if we multiply the analog result by 49 and divide by 100
        'since we are doing integer math we will get a value cvery close to the actual temperature in celcius.
        calculatedTemp = rawTempData * 49 / 100
        
        Return
    
    
    'Control the HEAT based on the current temperature
    
    PWMheatControl:    
    
    '    The heating procedure should follows below rules:
    '    - if calculatedTemp is >= 20*C, PWM value = 0%
    '    - if calculatedTemp is <20 but >=15, PWM value = 20% 
    '    - If calculatedTemp is <15 but >=10, PWM value = 40%
    '    - If calculatedTemp is <10 but >=5, PWM value = 50% 
    '    - If calculatedTemp is <5 but >0, PWM value = 70% 
    '    - If calculatedTemp is <=0 but >=-10, PWM value = 90%
    '    - If calculatedTemp is bellow -10*C, PWM value = 100%   
                 
        'set the PWM value based on what the temperature is
        If calculatedTemp >= 20 Then
            'the temperature is 20 deg or above, turn the HEAT off and indicate that the MIRROR is not heated
            heatPWMValue = 0
            Low led  'turn off LED
            Low HEAT  'turn off heat 
            heatON = notHeating
            
            'go into low power mode for a bit, when we wake up we will sample the temp again and see if we need to turn on the MIRROR
            nap 4   'nap for about a quarter second
       
       '
       '  From that point, I tryed several codes but no one is working. 
       '  So, please, fill up the "empty space" with necessary code.
       '  Thank you very much!
       '
       '
       '
       '
       '
       '
       '
       '
       '
       '
       '
       '
       '
       '
       '    Bellow is what the old code contains
       
       
       
        '
    '   ' 'loop through the PWM values a number of times
    '        For heatPWMCycleCounter = 1 To numberOfPWMCyclesNeeded
            
    '            'turn on the fan and indicator LED
    '            High HEAT  'turn on HEAT
    '            High led  'turn on LED
            
    '            'perform one cycle of PWM on the fan and LED
    '            For  heatPWMCounter = 1 To 10
                   
    '                'turn the HEAT and LED off if we have reached the end of its on time
    '                If heatPWMCounter > heatPWMValue Then
                        
    '                    Low led  'turn off LED
    '                    Low HEAT  'turn off HEAT
                        
    '                EndIf
                    
    '                'pause for a short time                
    '                pause PWMPauseTime
                    
    '            Next
                
    '        Next        
            
    '        'keep track of the fan state
    '        heatON = heating 
       
     
     
        EndIf           
            
        Return
    
    
    End
    
    
    'Startup, flash the LED to show that the system is operational
    startup:
       
       'turn on the LED for 2 seconds to indicate that the system is operational
        High LED            
        pause 2000
        Low led
    
    
      
        Return

  3. #3
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Hy! No one here able to write 4-5 code lines? Come on!

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,825


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Remember it is Christmas! Be patient and soon you will get your reply.

    Ioannis

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Quote Originally Posted by maciu1 View Post
    Hy! No one here able to write 4-5 code lines? Come on!
    looks you are included into " no one able " ones ...

    So, please, fill up the "empty space" with necessary code.
    Don't you think you're asking us too much ???

    You should be able to use some "SELECT CASE" statement to drive your PWM value ... or a retrieve table ( "LOOKUP" ) to directly choose your on/off PWM values

    Merry Christmas to you ...
    read you next year

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    @Acetronics, as I sad, I have no experience with PicBasic Pro and other stuff. For an experimentated guy, 5 minutes are too much in order to write the missing "link" in the code. That is my feeling.
    Happy new year!

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Last edited by Acetronics2; - 28th December 2012 at 19:35.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  8. #8
    Join Date
    Dec 2012
    Posts
    5


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Acetronics, if you have usefull ideas about my initial request, by my guest. Else, please, don't pollute my post with your amazing discoveries regarding old posts sent from others forums. You're so hard to follow...

  9. #9
    Join Date
    Sep 2011
    Posts
    1


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Just a beginner myself, but seeing as you're still looking for help, I'll give it a stab.

    I did a similar project to the one you referenced, except I used a 12F683. The main difference being that the 12F683 has one CCP pin, which means you can use the HPWM command and save a lot of headaches.

    I also used an LM34 which does temp. in fahrenheit.

    Here is the code which should be pretty easy to modify for your purpose:
    Code:
    'This program uses a 12F683 chip wired as follows:
    'Pin 2 (GPIO 5) - Status LED          Pin 7 (GPIO 0) - to LM34 Temp sensor 
    'Pin 3 (GPIO 4) - Low Speed LED       Pin 6 (GPIO 1) - high speed LED
    'Pin 4 (GPIO 3) - Not used (MCLR)     Pin 5 (GPIO 2) - pwm to fan mosfet
    
    ' Defines: 
    
        DEFINE	ADC_BITS	10	' Set number of bits in result
        DEFINE	ADC_CLOCK	3	' Set clock source (3=rc)
        DEFINE	ADC_SAMPLEUS  50	' Set sampling time in uS
            
    ' Registers:
    
    TRISIO = 1
    ANSEL = %00010001      ''Fosc/8 conversion speed  for 4mHz processor, AN0 analog input
    CMCON0 = 7
    ADCON0.7 = 1           'Right Justified (10 bit conversion)
    
    
    'Variables:
    
    Raw_Temp var word
    Temp Var word
    Avg_Temp var word
    LED1 var GPIO.5
    LED2 var GPIO.4
    LED3 var GPIO.1
    X var byte
    
    Raw_Temp = 0
    Temp = 0
    X = 0
    
    'Program Start:
    
    LED1 = 1      'Always on status light  
       
    START:
        LED2 = 0
        LED3 = 0  
        HPWM 1,0,1000
        Gosub GETDATA
            IF TEMP => 95 THEN GOTO MOTORSTART
        PAUSE 5000
        GOTO START
        
    MOTORSTART:   'Starts motor at full speed
        HPWM 1,255,1000
        PAUSE 1000
            GOTO THIRTY
             
    THIRTY:
        hpwm 1,77,1000
        LED2 = 1
        LED3 = 0  
            GOSUB GETDATA
            IF TEMP < 92 THEN GOTO START
            IF TEMP > 105 THEN GOTO SEVENTY
        PAUSE 5000
        GOTO THIRTY
    
    SEVENTY:
        HPWM 1,180,1000
        LED2 = 1
        LED3 = 1
            GOSUB GETDATA
            IF TEMP < 100 THEN GOTO THIRTY
            IF TEMP > 115 THEN GOTO FULL
        PAUSE 5000
        GOTO SEVENTY
        
    FULL:
        HPWM 1,255,1000
        LED2 = 0
        LED3 = 1
            GOSUB GETDATA
            IF TEMP < 110 THEN GOTO SEVENTY
        PAUSE 5000
        GOTO FULL
        
    GETDATA:
       Avg_Temp = 0
         for x = 1 to 5   'Hysteresis by averaging 5 samples  
            ADCIN 0,RAW_TEMP
            pause 5
            Avg_Temp = Avg_Temp + Raw_temp
            pause 1000
            next x
         TEMP = ((Avg_Temp/5)*49) / 100    'Farenheit conversion
         PAUSE 50
    '     SEROUT GPIO.4,4,["      Temp  ",#Temp,13,10]   'For debugging
        RETURN
        
    END

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    see next ...
    Last edited by Acetronics2; - 31st December 2012 at 12:33.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    Quote Originally Posted by maciu1 View Post
    Acetronics, if you have usefull ideas about my initial request, by my guest. Else, please, don't pollute my post with your amazing discoveries regarding old posts sent from others forums. You're so hard to follow...
    Hi, Maciu

    I have ONE useful idea for you ...

    Stop always begging and try some googling instead ...

    BTW ... LM35 AND 12F675 remind me to have crossed such applications on the web ... may be not PBP ( ? - one sure in Mikro C - ) , but, as you are just begging for code ... Hex file will be more than enough !

    Alain

    PS: I hate lazy beggars ... but you already knew it
    re PS : lazy ???

    I prove it : http://www.picbasic.co.uk/forum/showthread.php?t=12794
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Default Re: PWM for heating car's exterior mirrors

    the next part of the puzzle ...
    http://jeanclaude.grimaldi.perso.sfr...ePWMdouble%29/

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Sinusoidal PWM generation Using PIC 18f4431
    By oswalam in forum mel PIC BASIC
    Replies: 3
    Last Post: - 23rd February 2013, 15:49
  2. DT Multiple Software PWM and 18F2321 issue
    By microuser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th December 2012, 08:23
  3. Weird PWM Behaviour on 16F1825
    By RossWaddell in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th October 2012, 21:59
  4. TX module heating up ????
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th June 2010, 14:38
  5. 7805 heating
    By sirvo in forum Off Topic
    Replies: 10
    Last Post: - 9th February 2007, 22:16

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts