Programming freezing


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Alec,
    "I feel your pain" I drive a 62 Ford, try this:
    Code:
    '****************************************************************
    '*  Name    : auto_heater_controller.pbp                        *
    '*  Author  : Alec Noble                                        *
    '*  Notice  : Copyright (c) 2010 Alec Noble                     *
    '*          : All Rights Reserved                               *
    '*  Date    : 1/18/2010                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :                                                   *
    '*          :                                                   *
    '****************************************************************
    ;@ device pic16F628a
    ;@ device INTRC_OSC_NOCLKOUT
    @ __config _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _BOREN_OFF & _PWRTE_ON & _WDT_ON & _DATA_CP_OFF & _CP_OFF & _LVP_OFF
    DEFINE OSC 4
    CMCON = 7                   'port a digital i/o
    VRCON = 0                   'a/d voltage refernce disabled
    PortB = 0                   ' initialize all portB logic low
    TRISB = %00000000           'port b all outputs
    PortA = 0                   ' Initialize all outputs as low
    TRISA = %11000000           'a.7, a.6 inputs, all else output
    CCP1CON = %00001100		    ' Set CCP1 to PWM
    '**********************  aliasing I/O  ****************************
    
    up var porta.6      'up or increment button input
    down var porta.7      'down or drcrement button input
    heat var portb.3      'heater PWM output
    
    LED   var byte[10]       '10 bits - 1 for each led segment
    LED0 var PortB.0
    LED1 var PortB.1
    LED2 var PortB.2
    LED3 var PortB.4
    LED4 var PortB.5
    LED5 var PortB.6
    LED6 var PortB.7
    LED7 var PortA.0
    LED8 var PortA.1
    LED9 var PortA.2
    
    '**********************  create variables  **********************
    
    duty    var     byte        'variable for the dutycycle
    counter var     word        'variable to increment/decrement
    led_chk var     byte
    pwr     var     bit         'on/off bit
    preset  con     183        'minimum pwm duty value for low
    stp     con     2          'duty cycle steps
    
    '***********************  initialize variables  *****************
    
    pwr     =   1
    duty    =   15
    counter =   50
    LED     =   0
    'porta.3 =   0
    'porta.4 =   0
    
    '***********************  program begins here  ******************
    'pause 1000
    gosub adjust
    main:
    if up = 1 then  gosub increment
    if down = 1 then gosub decrement
    
       '********** display  ***************
       led = 0
    '    pause 1000
       lookdown2 duty, [93, 111, 129, 147, 165, 183, 201, 219, 237, 255], led_chk
       lookup led_chk, [%0000000001, %0000000011, %0000000111, %0000001111, %0000011111, _
                       %0000111111, %0001111111, %0011111111, %0111111111, %1111111111], led
    
    'Remmed out replaced above 
    '    if led.0 = 1 then portb.0 = 1
    '   if led.1 = 1 then portb.1 = 1
    '  if led.2 = 1 then portb.2 = 1
      ' if led.3 = 1 then portb.4 = 1
    '    if led.4 = 1 then portb.5 = 1
    '   if led.5 = 1 then portb.6 = 1
    '  if led.6 = 1 then portb.7 = 1
      ' if led.7 = 1 then porta.0 = 1
    '    if led.8 = 1 then porta.1 = 1
    '   if led.9 = 1 then porta.2 = 1
          pause 100
       toggle porta.3      'heartbeat
       goto main
       end
    increment:
    portb.1 = 1
    pause 5
    counter = counter + stp 'if so, increment
       if counter > 254 then counter = 254
    portb.1 = 0
    pause 5
    goto adjust
    
    decrement:
    
    portb.2 = 1
    pause 5
    counter = counter - stp
    if counter < 2 then counter = 2
    Portb.2 = 0
    pause 5
    
    
     
    goto adjust 
     adjust:
      duty = counter
     '********** duty_set **************      duty = preset + counter
      ' if duty >=255 then duty = 255
       'if pwr = 0 then  duty = 0
       hpwm 1, duty, 2000
    '**********  button_chk ***********
    return
    I used the lower b ports as indicators, you can change them back, as I am using a Microchip demo board. I scoped the output and it does what you want, i didn't fuddle much with your display except to remove some of my favorite pasta too many if thens for me.
    Last edited by Archangel; - 25th January 2010 at 09:18.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  2. #2
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Thanks Joe - I'll try it when get home tonight

    "LED var byte[10] '10 bits - 1 for each led segment
    LED0 var PortB.0
    LED1 var PortB.1
    LED2 var PortB.2
    LED3 var PortB.4
    LED4 var PortB.5
    LED5 var PortB.6
    LED6 var PortB.7
    LED7 var PortA.0
    LED8 var PortA.1
    LED9 var PortA.2"

    I tried this - I must have misread the manual, I thought the bit number had to be in brackets.

    "remove some of my favorite pasta too many if thens for me. " I'm still learning how to write clean code

    Thanks again - I'll post again tonight.
    Alec

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alec View Post
    " I'm still learning how to write clean code

    Alec
    <b>MEE TOOOO!</b> Darrel has busted me out over " PASTA" numerous times.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by alec View Post

    I tried this - I must have misread the manual, I thought the bit number had to be in brackets.


    Alec
    That's because you are right! Should be LED.0 = portb.0 . . . check Darrel's virtual port . bas and look for a post in PBP about it today. Still the PWM routines work, still struggling with the display, funny it works if using portB. Going to have to sleep more I guess.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  5. #5
    Join Date
    Feb 2005
    Location
    brookfield, ct, usa
    Posts
    24


    Did you find this post helpful? Yes | No

    Default

    Hi Joe
    Thanks for the links - I followed some of the threads and Melanie's explanation that Darrel refers to is easiest for my simple brain to wrap around...
    But, I have to resist the temptation to work on it more now - I'm supposed to be working my day job now. Should have more time tonight.

Similar Threads

  1. Data Programming Error at 0000
    By cpatnoi in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd May 2009, 04:37
  2. 16F676 programming problem
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th May 2009, 18:39
  3. Problems programming
    By Lionheart in forum General
    Replies: 4
    Last Post: - 7th December 2008, 17:51
  4. Programming Pins of PICs?
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th August 2007, 19:59
  5. PIC programming algorithm - where is it to find?
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th June 2007, 19:31

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