Quantcast
Channel: MEL PICBASIC Forum
Viewing all 4790 articles
Browse latest View live

Pic 12F675... No Blinky

$
0
0
I've been at this for hours. Please help.

Running on Windows 7 Ultimate

PBP 2.45, Microcode Studio Plus 2.1.0.7, MPLAB IDE 6.50, PICStart Plus

Microcode is configured for PBP compiler, MPASM Assembler and PICStart Plus Programmer

Everything seems happy. This has all worked before. I know it's me. :-P


Define OSCCAL_1K 1 ' Calibrate internal oscillator

LED Con 0 ' Alias GPIO.0 to LED

ANSEL = 0 ' Set all digital
CMCON = 7 ' Analog comparators off

mainloop:
Low LED ' Turn on LED connected to GPIO.0
Pause 500 ' Delay for .5 seconds
High LED ' Turn off LED connected to GPIO.0
Pause 500 ' Delay for .5 seconds

Goto mainloop ' Go back to mainloop and blink LED forever

End
I copied this code from the forum as well as trying several others. Nothing seems to work.

From Microcode, I hit "Compile and Program". It opens MPLAB. I enable the programmer, wait, and hit the program button.
MPLAB pops up a configuration warning:

"Configuration Memory has not been updated. Press "Yes" to accept the current configuration or "No" to abort the operation.

I don't know how to update the configuration so I've been hitting "yes".

The PICStart "programming" light comes on and seems to program.

Another Pop-up... "Calibration Memory Not Programmed"... "Calibration Memory is already programmed."

I hit ok.

"Programming/Verification completed successfully!"

I pull the PIC and insert it into the breadboard.

No joy.

Breadboard:

Vdd +5v
Vss Common
GPIO.3 (Pin 4) connected to +5 through 1k resistor
GPIO.0 (Pin 7) connected to LED to 270 ohm resistor to common.

LED orientation checked.

I reinstalled all software using "Administrator". Everything seems ok. Where am I going wrong?

Please help. THANK YOU!

Ross

Epic programmer

$
0
0
Would like to trade a Epic programmer for the latest hard copy of PBP3. Someone might use it for? My old copy of 2.6 is flaking apart with all my notations over the years. Sorry no parallel cable with it.

16F88 internal oscillator ?

$
0
0
Have never used this chip before, wondering about the internal osc as there may be more to it than meets the eye. Looked at some posts which are dead ends.

First of all, does it default to the internal osc? Should I just do nothing?
I tried this OSCCON setting but no luck.

I know my code will work fine if I can get over the hump on this -- seems it's always a configuration problem that slows me down.

Thanks kindly for any help. I just need the int osc at 4mhz, which will be fine.

OSCCON = %01101000 '01111000 is 8mhz

ANSEL = 0
CMCON = 7

Randomize 2 values -- ideas?

$
0
0
I have 2 variables --

BRON VAR 224

BROFF VAR 0

I know I can use SWAP to do just that but trying to figure out a way I can possibly setup another variable that will give me either 224 or 0 on a random basis. I'm thinking it's impossible but maybe someone can offer something. RANDOM uses too many possibilities but my goal, like I say are just these 2 values. And it wouldn't have to be a prefect random, just the appearance of it. ??

Thanks, although I think I'm dreaming on this.

PicBasic Pro 2.46 Manual.

$
0
0
  • Hi,

    I have a little dated version (2.46) of the PicBasic Pro compilator. I would like to know where to find a manual for my version. Taking the latest versions of the manual very often I find the instructions that my version does not support.

    Thank you all for your help.




Need to drive 40 pins on variable change, is there a way to do it in elegant way?

$
0
0
Hello.

I'm building a nixie clock, which does not uses any specific decoder ICs or multiplexer. Instead, all nixie digits are connected to individual MCU pins via transistors. It uses DS1302 as clock source. Time received from DS1302 is converted into single number in 24 hour format, for example, it time is 15:53, this number will read as 1553. Using DIG statement I'm extracting individual digits from it, so I have 4 variables, called T1-T4, which have data for individual number to be displayed on specific digit. The pin numbers to which nixies are connected are aliases in the following way - A0-A9 for numbers in 1st digit, B0-B9 for numbers in 2nd digit, C0-C9 and D0-D9 for 3rd and 4th digits correspondingly. So now, to display time, I need to run the following code:

IF T1=0 THEN A0=1
IF T1=1 THEN A1=1
IF T1=2 THEN A2=1
IF T1=3 THEN A3=1
IF T1=4 THEN A4=1

and so on, total, 40 lines (not shown is code for extinguishing all non-used numbers, but I'm doing it at same time for all digits)

So question is, is there a way to avoid all these if-then lines and do it somehow in more elegant way?

Thanks in advance!

A strange problem

$
0
0
  • Thanks Acetronics, you did a great job. RTFM is the answer.




Elapsed Timer on 12F683 doesn't work

$
0
0
I have this code example:

INCLUDE "DT_INTS-14.bas"
INCLUDE "ReEnterPBP.bas"
INCLUDE "Elapsed_INT.bas" ; Elapsed Timer Routines

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _ClockCount, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE TMR1_INT ; Enable Timer 1 Interrupts

GOSUB ResetTime ' Reset Time to 0d-00:00:00.00
GOSUB StartTimer ' Start the Elapsed Timer

Main:
IF SecondsChanged = 1 THEN
SecondsChanged = 0
LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
ENDIF
GOTO Main
And get under PBP3 this error message:

ERROR: Variale wsave3 position request 416 beyond RAM-END 191
ERROR: Variale wsave2 position request 288 beyond RAM-END 191

Who can kindly help me?
Attached Images
 

Hitachi vs Sitronix LCD

$
0
0
I recently purchased several of these: https://focuslcds.com/product/8x1-st...xbsbsw6wf55xaa. They are a simple (or so I thought) 8 character LCD. I have, and use, 4 line Hitachi HD44780 all the time and the Sitronix ST7077 is advertised as pin compatible.

I have the following code running on a 16F88 and it drives a 4 line Hitachi just fine, but not a blink, flicker, or sparkle from the Sitronix. Any idea why?

PS: I've tried adjusting LCD_LINES, DATA, and COMMANDUS... I've wired 2, fresh from the box, breadboarded them up in parallel - nothing.

Code:

#CONFIG
  __config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF
  __config _CONFIG2, _FCMEN_OFF & _IESO_OFF 
#ENDCONFIG
DEFINE OSC 4
                                           
TRISA = %00000000                                                 
TRISB = %00000000                                                     
OSCCON = $60
ANSEL = %00000000

DEFINE LCD_DBIT 0
DEFINE LCD_LINES 2
DEFINE LCD_COMMANDUS 2000  'Set command delay time in us 
DEFINE LCD_DATAUS 50      'Set data delay time in us

Pause 500     

MAIN:
  TOGGLE PORTB.2
  Lcdout $fe, 1  ' Clear LCD screen
  PAUSE 100
  Lcdout "Hello"
  Pause 500      ' Wait .5 second
  Lcdout $fe, 1 
  PAUSE 100
  Lcdout "World"
  Pause 500     
Goto MAIN

In need of accessing more than 255 bits in a byte/word array.

$
0
0
I am in need of accessing more than 255 bits in a byte/word array while using a variable bit index. My understanding is that it can be done with a constant index but not with a variable index.
This would really be helpful to our organization.

Thanks

In need of accessing more than 255 bits in a byte/word array.

$
0
0
Hello all.

I'm sure this question has been asked a million times before but has anyone found a way to access more than 255 bits in a byte/word array with a variable bit index?

Any and all answers are appreciated.

Instant Interrupts and a 18F8680

$
0
0
I am trying to use the RX1_INT in DT's Instant Interrupts with this chip and I get an error (actually 3 of them):
NODE1.ASM (785) : Symbol not previously defined (RC1IF)
" " (1365) "
" " (1390) "

I have used these great tools before without ever looking under the 'hood'.
Any guidance would be helpful.
Regards.

Solar Panel battery charger

$
0
0
Hello folks,

Been a long time since I have posted and played here. . .. I am now retired. ..

I have a situation. . .

I have a 24 volt battery system for off the grid power. i have a lot of panels that charge the batteries,
and I want to make a charge controller out of mosfets. . . My problem comes in reading the battery
voltage without the panels affecting the reading. . .

Panel Voltage varies between zero and 40 volts.

I want to charge the batteries to 28 volts and shut off the panels.

My problem lies in the instant the panels are connected, the voltage shown on my meter is almost
instantly at 28 volts, because the panels are shoving 30+ volts into them at 50 amps. Yet the
batteries are actually not fully charged.

Anyone know of a circuit that i can use to accomplish this feat?
iSeems like everyone else can figure it out, but me.

Dwayne

Windows 10 which MpLab

$
0
0
Just purchased a new computer with windows 10 I’m using MPLab 8.90 I think should I keep that set up or should I go to MPlab X. I’m not doing any of the new processors at this time and this original set up has worked fine for the last 10 years or more.
Any ideas or suggestions is MPLab x difficult to set up

Pic 12F675... Pulling GPIO.3 Low resets program

$
0
0
I've been at this for hours... so bare with me please.

I have a 10k pullup on port 3 (GPIO.3) and set it to input. I have the wiper of a 10k pot connected to GPIO.2 and have it set to analog input. I am not currently using it in the program but plan to, so ADCON0 and ANSEL reflect the planned future use (in case I have something screwed up there). Port 2 is the only analog input port.

I have an LED and Relay connected to ports 0 and 1 respectively.

With the program below, an LED and a Relay turn on and turn off every two seconds repeatedly.

But when I push a button connecting port 3 to ground, all action from the LED and Relay stops (as though I've shorted out the 5v supply). I have checked the supply voltage at the pins of the processor and grounding port 3 has no effect on the supply voltage.

When the button is released, the LED and Relay return to normal function.

NOTE: I added the toggling relay just before "Main" to help me understand what was happening. Pushing the button apparently resets the chip because the relay "buzzes" when it is pressed and released.

Why would bringing input port 3 to ground cause a reset?

Thank you!

Ross


Code:

      Define OSCCAL_1K 1  ' Calibrate internal oscillator
 
  TRISIO = %00111100  ' GPIO.2,3,4 and 5 INPUTS, GPIO.0 and 1 OUTPUTS
  ADCON0 = %10001001  ' Turn on A/D module, Enable AN2, R Justify Result
  ANSEL  = %00100100  ' Fosc /32, Set AN2 analog, the rest digital
  CMCON = 7          ' Analog comparators off
  WPU = %00110000    ' Turn on weak pullups on GPIO.4 and 5
 
  LED VAR GPIO.0
  RELAY var GPIO.1
  I var byte
 
  for i = 1 to 10      'This put in to buzz relay at start of program
  toggle relay     
  pause 50
  next i
 
Main: 
    HIGH LED        'Turn on LED
    low relay        'Turn on Relay
    pause 2000     
    LOW LED        'Turn off LED
    high relay        'Turn off Relay
    Pause 2000
    goto main        'Do it again...
    end


"Program Memory Errors" MPLAB using PicStart Plus

$
0
0
Hi all...

I'm battling my way back into hobbying with Picbasic Pro and having a rough time.

I first had trouble with getting my config stuff worked out. Shortly after I got that working, I started getting "Program Memory Errors" from MPLAB while programming a 12F675.

It was working! I've been programming the pic over and over. Two different pics. All of a sudden, it's not happy? It worked then it didn't work then it worked... now it doesn't work at all.

So if you have any thoughts on this I sure would appreciate your support! I know I'm leaning heavily on the forum right now. I'm just burned out. I've searched for answers to this here and on the web. I'm getting really tired of reading at this point. I just keep thinking it shouldn't be this hard to get off the ground.

Any help here is greatly appreciated!

Thank you!

Ross

Having troubles with READ / WRITE confirming it works...

$
0
0
Hi all!

I am using a 12f675 to control speed, direction, acceleration and deceleration of a dc motor. Speed and motor direction are both controlled by reading the position of a potentiometer. The potentiometer has a detent midway through it's range. This position is speed zero. Clockwise of speed zero increases motor speed clockwise. Counterclockwise of speed zero energizes a relay reversing polarity to the motor and increases speed in a counterclockwise direction.

I am in the beginning of programming. The code below is meant to allow capturing the pot center position and storing it in a word variable in two eeprom locations. This happens by holding gpio.3 LOW for two seconds while power is applied to the circuit board. After two seconds, an A/D conversion captures the center position into a word variable "POT_CNTR". The word is stored in two eeprom locations, low byte and high byte.

Just before the program passes to MAIN:, it reads the two eeprom locations back into word variable "POT_CNTR".

Being the newbie programmer that I am, and having no LCD connected to the processor, I need a way to insure that I have, in fact, captured a good number into "POT_CNTR" before I move on. The programming below is meant to do that, audibly, by buzzing the directional relay and by using an LED on the board to provide visual feedback as I turn the pot left and right.

But alas... it doesn't work! Ha!

I provided some hysteresis around zero position (plus or minus 10 of "POT_CNTR") to provide some room around position pot zero. Counter clockwise of pot zero and the LED should turn on steady. Clockwise of pot zero and the LED should blink repeatedly. When the pot is located near center position, the LED should turn off.

That's what I wanted it to do. Instead it just flashes repeatedly like it is always CW of pot center position (pot zero).

It you were bored enough to have read all of this, I would appreciate any help you may have for me!

Thank you!!!

Ross


Code:

    Define OSCCAL_1K 1  ' Calibrate internal oscillator (4mhz)
 
    TRISIO = %00111100  ' GPIO.2,3,4 and 5 INPUTS, GPIO.0 and 1 OUTPUTS
    ADCON0 = %10001001  ' Turn on A/D module, Enable AN2, R Justify Result
    ANSEL  = %00100100  ' Fosc /32, Set AN2 analog, the rest digital
    CMCON = 7          ' Analog comparators off
    WPU = %00110000    ' Turn on weak pullups on GPIO.4 and 5
 
    DEFINE ADC_BITS 10          ' Set number of bits in result
    DEFINE ADC_CLOCK 2          ' Set clock source (32 Tosc)
    DEFINE ADC_SAMPLEUS 50      ' Set sampling time in uS
   
'*******************************************************************************
'VARIABLES:
   
    MOTOR VAR GPIO.0        'MOTOR ON PIN 2, START WITH IT OFF
    LOW MOTOR
    LED VAR MOTOR
   
    RELAY var GPIO.1        'RELAY DETERMINES MOTOR DIRECTION, PIN 3
    HIGH RELAY              'START WITH RELAY DE-ENERGIZED
   
    BUTN VAR GPIO.3          'START/STOP SWITCH (ALSO REMOTE FOOT SWITCH), PIN 5
                            'BUTTON IS ACTIVE LOW (WHEN PUSHED)
                           
    POT_CNTR VAR WORD      'THIS VALUE TO BE STORED IN EEPROM DURING
                            'INITILIZATION ROUTINE.
                               
    I var byte              'VARIABLES USED FOR GENERAL COUNTERS. INIT AS ZERO.
    I = 0
    J VAR BYTE
    J = 0                 

    SPEED_NEW VAR WORD      'VARIABLE TO STORE A/D VALUE
    SPEED_OLD VAR WORD      'VARIABLE TO STORE PREVIOUS A/D VALUE
   
    DIR VAR BIT            'VARIABLE TO DETERMINE CW OR CCW REVOLUTIONS
   
    RUNN VAR bit            'RUN / STOP BIT. MACHINE COMES UP IN STOP MODE
    runn = 0
 
    PAUSE 500              '1/2 SECOND PAUSE BEFORE CONTINUING

'******************************************************************************

'INITIALIZATION ROUTINE... POT IS TURNED HALF-WAY TO MIDDLE POSITION AND
'START/STOP SWITCH (BUTTON SW) IS PUSHED AND HELD WHILE MACHINE POWER IS TURNED
'ON. AFTER TWO SECONDS, MACHINE WILL BUZZ TO INDICATE IT CAPTURED POT CENTER 
'POSITION AND LOADED IT INTO EEPROM LOCATIONS 0 AND 1 (LOW AND HIGH BYTES) OF
'WORD VARIABLE. 
   
INITIALIZE:
    WHILE BUTN = 0          'CHECK FOR BUTTON PRESS
    IF I = 100 THEN
    ADCIN GPIO.2, POT_CNTR
    WRITE 0, POT_CNTR.BYTE0
    WRITE 1, POT_CNTR.BYTE1
    GOSUB BUZZ
    I = 0
    WHILE BUTN = 0
    PAUSE 20
    WEND
    ENDIF
    PAUSE 20
    I = I + 1
    WEND

'******************************************************************************
'THE POT ONLY NEEDS TO BE INITIATED ONCE AS THE EEPROM SHOULD HOLD THAT VALUE
'AFTER POWER IS REMOVED. THE FOLLOWING LINES READ THE LOWER AND UPPER BYTES
'FROM THE EEPROM BACK INTO THE VARIABLE POT_CNTR (IN CASE INITIALIZATION WAS
'NOT PERFORMED AT POWER-UP).   

    READ 0, POT_CNTR.BYTE0
    READ 1, POT_CNTR.BYTE1
   
'******************************************************************************   

MAIN:
    GOSUB GET_POT
    GOSUB CHECK_POT
    GOTO MAIN
    END

BUZZ:
    for J = 1 to 10
    toggle relay        'This put in to buzz relay. Programming feedback
    pause 20
    next J
    return

GET_POT:                    'READ POT POSITION AND PUT IT IN VARIABLE SPEED_NEW
    ADCIN GPIO.2, SPEED_NEW
    RETURN
 
'TURNING THE SPEED POT CCW FROM CENTER POSITION CAUSES LED (ON MOTOR CIRCUIT) TO
'COME ON. TURNING THE SPEED POT CW FROM CENTER POSITION CAUSES LED TO BLINK.
'LED IS OFF WHEN THE POT IS NEAR CENTER POSITION

CHECK_POT:
    IF (POT_CNTR - 10) <= SPEED_NEW <= (pOT_CNTR + 10) THEN
    LOW LED
    ENDIF
    IF SPEED_NEW < (POT_CNTR - 10) THEN
    HIGH LED
    ENDIF
    IF SPEED_NEW > (POT_CNTR + 10) THEN
    TOGGLE LED
    PAUSE 50
    ENDIF
    RETURN

Adafruit 12 key touchpad

$
0
0
I'm trying to get an Adafruit 12 key capacitive touchpad (https://www.adafruit.com/product/1982) going. I don't think I'm too far off, but the multiple registers, Arduino-centric tutorial, and my own lack of experience leave me struggling. On a 16F88, I get inconsistent readings and cannot tell if it's the Adafruit part, some problem with my understanding of I2C statements, or general lunkheadedness. The link contains all in unique information I can find...

I'm hoping someone has a minute to comment...

Code:

#CONFIG
  __config _CONFIG1, _INTRC_IO & _WDT_OFF & _PWRTE_OFF & _MCLR_ON & _BODEN_OFF & _LVP_OFF & _CPD_OFF & _WRT_PROTECT_OFF & _DEBUG_OFF
  __config _CONFIG2, _FCMEN_OFF & _IESO_OFF 
#ENDCONFIG

DEFINE OSC 8

'-----DEBUG (SERIAL) SETUP----------------------------------------
DEFINE DEBUG_REG PORTB
DEFINE DEBUG_BIT 3
DEFINE DEBUG_BAUD 2400
DEFINE DEBUG_MODE 0

OPTION_REG = %00001111                                              ' PULL-UPS ON, FALLING EDGE
TRISA = %00000000                                                  ' Set PORTA output
TRISB = %00000000                                                     
OSCCON = %01110000
ANSEL = %00000000

T_ADDR VAR BYTE
T_ADDW VAR BYTE
T_REG VAR BYTE
KEYS VAR BYTE[2]

'-----PORT SET-UP------------------------------------------------- 
SDA  VAR PORTB.1
SCL  VAR PORTB.0
T_ADDW = %10110100
T_ADDR = %10110101
T_REG = $0

i2cwrite SDA, SCL, T_ADDW, $5E, [%00111100] , I2CERR
i2cwrite SDA, SCL, T_ADDW, $0, [%11111111]  , I2CERR


MAIN:
  PORTA = 0
  PAUSE 2000
  PORTA = 255
  PAUSE 50
  GOSUB READKEYS
GOTO MAIN


READKEYS:
  I2CRead SDA, SCL, T_ADDR, T_REG, [KEYS[0], KEYS[1]], I2CERR
  DEBUG "  ?--P110000000000", 13
  DEBUG "  ?--P109876543210", 13
  DEBUG "k: ", BIN8 KEYS[1], BIN8 KEYS[0], 13
RETURN

I2CERR:
DEBUG "PROBLEM "
RETURN

digital integrator algo for bipolar sigs?

$
0
0
Thanks Darrel,

This is actually a slower approach than what I am doing. It is more nicely coded - but the branching would greatly reduce the speed. I'm trying to run a loop that will iterate at over 100kHz, and I am not concerned with regular periodicity, ie if it runs a few times at 125kHz and a few periods are at 110kHz all is well.

i have proportional control running at 800kHz. However when i add the integral calculation, check for saturation and sum the result, it's at nearly 50kHz. I've managed to get the calculations as clean as possible, but the IF/THENs are killing me.

I was really hoping a CE out there would have a suggestion as to how to deal with this. For instance, the first condition in my current loop checks to see if the result is between 00 and FF, then writes it, then immediately returns to the sample. It only checks for saturation if that condition fails, resulting in an aperiodic signal, but it is only slow when the output is saturated - so I'm not worried about that.

Even if it requires raw assembly I'll be happy to implement it. I'm also trying to come up with a very long routine that would branch only once or twice while continusously resampling and writing when not saturated.Please start a thread in the appropriate forum for detailed technical help. This is just a chat box, your post will disappear quickly.

Motor Control Circuit (JPG Attached) for scrutiny and discussion...

$
0
0
Hi all!

I'm NOT an electronics engineer! That said, I am doing my best. What I do not have is a scope to look at the PWM output and so I am leaning on you good folks to guide me. Please.

Pardon my sketch. I never could draw a descent relay. :-P So I drew it like it is wired. The relay is used to reverse polarity to the motor outputs. I forgot to draw a diode for the motor supply circuit to the relay contacts but it's in there too.

I am using a logic level N-Channel Mosfet. This is where I am the most unsure. I do not know what resistors or capacitors I should use to give it a clean PWM signal. I have drawn up what I currently have but it does not appear to work. It does work when I just make the GPIO.0 High or Low, turning the MOSFET on and the LED on and off. That works. Also, the relay works fine. But there is no joy with the PWM. I suspect the resistors and capacitor.

I don't read electronics data sheets too well. So I don't know if the MOSFET gate input is high impedance or if it turns on like an LED drawing a lot of current. I suspect high impedance but I put a resistor R1 (270 ohms) in series with the gate so I don't source too much current from the PIC output pin. Don't know if it was needed (or wanted).

The 15k resistor to ground was suggested from another similar circuit to prevent the MOSFET from staying on. And the .1 uf cap to ground was suggested in the Picbasic Pro manual to clean up the PWM output signal. Sooo... I hodgepodged all three in there. That's my mechanical mind working on electronics. Moo HAA HAA!

If a couple of electronics geniuses could look this over I would be much obliged!

GPIO.4 and 5 were for adding an external crystal which I haven't done so they are disconnected. I have turned on the internal pull-ups and made them inputs in the program.

I'm sorry the attached jpg is coming in sideways. :-P I will follow this posting with my current program.

Thank you!

Ross
Attached Images
 
Viewing all 4790 articles
Browse latest View live