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

Hserin / out Woes..

$
0
0
Hi All..

Am using this code as a simple password check on a serial link :-

Code:

hserout [":- "]
            hserin 65535,bed, [pass (0)]: hserout [pass (0)]
            hserin 65535,bed, [pass (1)]: hserout [pass (1)]
            hserin 65535,bed, [pass (2)]: hserout [pass (2)]
            hserin 65535,bed, [pass (3)]: hserout [pass (3)]
            hserin 65535,bed, [pass (4)]: hserout [pass (4)]
            hserin 65535,bed, [pass (5)]: hserout [pass (5)]
            hserin 65535,bed, [pass (6)]: hserout [pass (6)]
            hserin 65535,bed, [pass (7)]: hserout [pass (7)]
            hserin 65535,bed, [pass (8)]: hserout [pass (8),10,13]
           
            IF ("2" = pass(0))and ("9" = pass(1))and ("9" = pass(2))and ("7" = pass(3))and ("9" = pass(4))and ("2" = pass(5))and ("4" = pass(6))and ("5" = pass(7))and ("8" = pass(8)) THEN correct

There are nine decimal digits which have to be correct.... but some times it fails on the last digit, but not always ?? If I cut the pass word to 4 digits it fails also on the last digit ????

My question is... is there a more elegant way of doing the above? I still want to see each char as typed...wich rules out a string of words.

But more I need it to be reliable..I am using a 4 Meg Xtal my defines are :-

Code:


    DEFINE OSC 4        'Set oscillator in MHz
    'OSCCON = $60    '4 Megs
   
    DEFINE HSER_RCSTA 90H  'Set receive status and control
    DEFINE HSER_TXSTA 24H  'Set transmit status and control
    DEFINE HSER_BAUD 9615  'Baud Rate
   
   
    ADCON1 = 7 ' Turns Analogs off
    CMCON0 = 7 'Disable both comparators
    ANSEL = 0  ' Set all analog pins to digital

thank you for looking....

sending data - numbers between PICs

$
0
0
I must not be thinking about this right. I need to send an "R", either a "2" or "4", and then a 4 digit decimal number from one PIC to another using hserin and hserouthserin and serout2. Ideally I would like to be able to detect the R when the R##### characters come but first things first. Using a PIC16F688 at 8MHz at 1200 baud.

This is what I send:
hserout [ "R", "2", dec4 volts] 'where volts is a 4 digit decimal number

This is how I am looking for it on the receiving PIC:
hserin 800, rinse,[syncr, drip, dec4 volts]

I then print it to a computer for display using:
serout2 Txd, 813, ["got it_1", 9, syncr, 9, drip, 9, dec4 volts, 13]

Nothing shows up as output, not even the "got it" text, as if it never gets to this point. I would like to be able to, depending on whether drip is a "2" or a "4", do different things. I think I've done this very thing on other projects so I'm mystified why this doesn't work.

Thanks for any help.

microcode studio plus default template

$
0
0
I love MCS+ to death! I use it with mostly with my MikroElektronica EasyPic V7 board but sometimes with the MELabs LabX1.

I find the "New" program header template somewhat wanting and would like to substitute my own instead. Is there a way to access the current one and edit it? Yes, I know I can add my name to the existing one using the editor options but I want more control.

I'd like to hit "new" and have my template which is more substantial, pop up.

Thanks.

Looking for Elapsed_DN.bas by Darrel Taylor

$
0
0
I know he passed away, but I'm looking for a file he had for using his Elasped timer for counting down rather then
counting up.

This is the demo code for it but it needs Elasped_DN.bas

Code:

' Define LCD connections
DEFINE LCD_DREG PORTC  ' Set LCD Data port
DEFINE LCD_DBIT 4      ' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTC  ' Set LCD Register Select port
DEFINE LCD_RSBIT 2      ' Set LCD Register Select bit
DEFINE LCD_EREG PORTC  ' Set LCD Enable port
DEFINE LCD_EBIT 3      ' Set LCD Enable bit
DEFINE LCD_BITS 4      ' Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2      ' Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 'Command delay time in us
DEFINE LCD_DATAUS 50 'Data delay time in us

DEFINE  OSC 4

INCLUDE "Elapsed_DN.bas"  ; Elapsed Timer Routines

ZERO_LED  VAR PORTB.3

ANSEL = 0                ' All Digital
ANSELH = 0
LOW ZERO_LED              ' start with LED OFF
OPTION_REG.7 = 0          ' enable PORTB pull-ups
PAUSE 250               
LCDOUT $FE,1              ' Initialize LCD
PAUSE  250

Days = 1                  ' set initial time
Hours = 1
Minutes = 3
Seconds = 10

GOSUB StartTimer          ' Start the Elapsed Timer

Main:
CountDown = !PORTB.0
  IF SecondsChanged = 1 THEN 
    SecondsChanged = 0
    LCDOUT $FE,2, DEC Days,"d-",DEC2 Hours,":",DEC2 Minutes,":",DEC2 Seconds
  ENDIF
  IF ZERO_LED != ZERO THEN ZERO_LED = ZERO
GOTO Main


If would be greatly appreciated is someone has this file they can share.

Thank you

DT-INTS and SSP1_INT

$
0
0
I'm able to use the following interrupts from DT-INTS:

1. RX1_INT
2. RX2_INT
3. TX1_INT
4. TX2_INT
5. TMR1_INT
6. TMR0_INT

When I try to use SSP1_INT, the program hangs waiting for the code to execute in the MSSP1 interrupt. I can remove the interrupt and use a GOSUB to execute the MSSP1 module but can't figure out why using the interrupt isn't working. I can confirm that the code goes past the

@ INT_ENABLE SSP1_INT

but it never goes into the SSP1 interrupt. Any thoughts?

PN532 Modules

Little help with a LM2596 inverter...

$
0
0
Hello all,

Been away for a while, hope everyone is well. I've got a question in regards to the LM2596 INVERTING switcher. I'm brain frying over a "shutdown", or rather a "start up" circuit for this rig. Can you fine folks check out these datasheets real quick and let me know if I'm over-thinking things (which would not be abnormal for me :smile:).
I would like to turn ON the switcher with +12vdc...
It appears to me that these two datasheets conflict each other?
http://www.ti.com/lit/ds/symlink/lm2596.pdf FIGURE 40
http://www.onsemi.com/pub_link/Collateral/LM2596-D.PDF FIGURE 24
Thanks a ton guys,
Chris

PIC18F27J13 Peripheral Pin Select (PPS)

$
0
0
Hi All,

I am experimenting with the PIC18F27J13 and I am having difficulties using the peripheral pin select (PPS) options.
I am trying to set a PWM output function to re-mappable pin RP2 (RA5 - Pin 7)
I am working from datasheet DS3997A which is listed as a "Preliminary" datasheet but I can find no others on the Microchip website.

"Section 18.0" states that the device has "seven CCP (Capture/Compare/PWM) modules designated CCP4 through CCP10."

"Table 10-14: SELECTABLE OUTPUT SOURCES" shows CCP1/P1A (ECCP1 Compare or PWM Output Channel A) is output function 14

My confusion lies in the mis-match between the CCP4 and CCP1 statements listed in the above references.
Can anyone shed some light on how to re-map output function 14 to re-mappable pin 2 (RP2)?

Cheers
Barry
VK2XBP

Problem Make Speedometer with Hall Effect Sensor and RF-RS232

$
0
0
Hello,

I want basic telemetry system and i will send voltage, current, speed and temperature values this system. I have 3 questions about this situation.

First Question:
- 18F4550 has one rx one tx inputs. I want to use together RF and RS-232 communication on receiver card. I use microcontroller' s tx-rx inputs for RS-232 communication and whatever inputs for Dorji RF (DRF 7020D27). For example as a Symbol TX PORTC.0 and Symbol RX PORTC.1.

Second Question:
- I have hall effect sensor' s code for speedometer as follows and i don't understand this code. Could you explain this code for understanding?

speed_Measurement:
pulsperiod = PulsIn PORTD.7,0
temporary1 = 250000/pulsperiod
speed =temporary1*2.772 ;5.544 for 4 magnets
speed1=speed

And Finally:
- I think ACS755-150 for current measurement but how i don' t know high DC voltage values. For example as a 150 VDC.

Already thanks a lot for yours help :)

Delay without using pause

$
0
0
I'm developing one of my old projects and I've hit a stumbling block. The old code simply read 4 x DS18B20's and use the data to control the out put to a heat via Henrik's PID routine. It's been working fine for 5 years now, but I want to add 4 x AM2302's to monitor the humidity and also monitor the temperature in its location. The code includes DT's interrupts, DS18B20, and all digital "library files", and thus a lot of the timings for the period each heater is on is done in the background, and the main code consists of a simple loop that reads the sensors and does the maths.

However with four sets of information for each of the four viavriums the 20 x 4 LCD is becoming a little crowded. So what I really want to do is to display Viv(x), temp1, humidity1, temp2 on a single line on the LCD. No problem in coding the line to do this, but as the program runs so fast through the data it's impossible to read. The simple way is to add a pause statement so for example the code pauses for 2 seconds before retuning to the main program loop and advancing on to the next set of data. But this then delays the speed at which the probes are monitored and by the time the loop is back to probe 1 the temperature could of gone past the set point, as it's not monitored in real time.

My hair is now white, and I'm half bald trying to resolve this - the nearest I came was to use some form of counting loop within the main loop, that when it tripped over a set value it increased the value of viv(x) by one, so in essence the main code ran at real time speed, but the LCD was only updated every second or so and thus wouldn't hold up the realtime monitoring. Unless any of you guys can come up with a better suggestion

Account hacking ?

$
0
0
Hey, someone tried to log in my account last 15 minutes, his IP is 117.169.1.34. Used an ip tracker and pointed me to a Chinese town. Are we unter attack from little Chinese people ?! xaxaxa

DHT Sensor Library

$
0
0
After helping out others a few times here on the forum implementing DHT series Humidity/Temperature sensors,
I thought I might put together a DHT Sensor support library for PBP and hopefully others can benefit from it.

I must give a huge thank you to "Scampy" on this forum, as he was key to this library getting completed.
He provided great improvement suggestions and did the vast majority of the real world testing of the library in its various versions.

A Note of caution when using this library.
Retrieving data from these sensors is time sensitive since once initiated the sensor streams all of the data bits until it's finished.
Because of this fact, if you are using Interrupts you may want to disable them during the Sensor read sequences.
This information is highlighted in the source code at the points where an Interrupt may cause issues.

The DHT family of sensors uses a proprietary 1-wire interface where the data sent by the sensor is a time-driven high pulse.
The sensor sends a "0" as a high pulse of 26-28us long and a "1" as a high pulse of 70us long.
So some means of measuring the duration of a High signal is required for accurate use.

There are many ways to communicate with and retrieve data from these sensors and measuring the pulses, from using
PIC HW timers to using pure PBP software commands, each with its own benefits.
While HW timers are very accurate, it does require the Timer HW module of the PIC.
Using the Timer module to aid in the communication with the sensor can limit the ease of implementation of a library.
Once you settle on a Timer to use, surely someone will not be able to use that Timer module for one reason or another.
This will lead to customization of the library by the user, so I have opted for a software approach instead.

The consistent stumbling block with reading the data from the sensor, that I noticed, was the manual computation of
timing/count values to determine data "0s" and "1s" coming from the sensor for various oscillator speeds.

So this lead me to the primary goal of a library that would automatically compute these values.

With the primary goal established, I came up with following objectives for the library that I believe to have accomplished.

Code:

1. Software Implementation
    * (not bound to PIC hardware modules)
    * Use any available Digital Input Pin on the PIC
    * Facilitate portability across various PIC MCUs and User Apps
    % Achieved
        - Similar to a "Function" call
2. Standard PBP Commands
    * Stay away from ASM (for the most part)
    * Support for PBP v2.6 and higher
    % Achieved with PULSIN (and a small amount of ASM for ease of use)
3. Consistent Interface Supporting Multiple Sensor Types
    * All parameters passed and data returned from the library consistent for all Sensor Types supported
    % Achieved
        - Supports DHT11, DHT21, DHT22, AM2302 sensors (uniform parameters)
        - All data returned is consistently formatted
4. Support for Multiple Concurrent Sensors
    * Support scalability from 1 to many sensors
    % Achieved - Currently has 4 sensors but can be scaled up or down
5. Ease of Use
    * As few "knobs" to manually turn as possible
    * Make it an Include file
    % Achieved
        - (3) Statements to invoke: Sensor Number=, Sensor Type=, Gosub DHT_READ
        - (1) Alias for each sensor used, (1) Constant for MAX Sensors, (1) DEFINE for PULSIN_MAX, (1) Standard DEFINE OSC x
        - Variability of internal settings computed automatically at compile time
        - Single Include File
6. Quick Response Time
    * Return the data or errors as fast as possible
    % Achieved
        - User parameters, Comms Initialization and Timeout errors are checked
        - Short-circuit logic returns to calling program upon errors
7. Support a Wide Selection of MCU Speeds
    * Support as many, if not all of the supported PBP "DEFINE OSC" values
    % Achieved
        - Supports 8,10,12,16,20,24,25,32,33,40,48 & 64 MHz OSC values.
        - (3 & 4 MHz not supported in this library)
8. Robust Error Checking/Reporting
    * Error-check user and sensor data
    * Return Error values for user evaluation
    % Achieved
        - Alarms and Messages during compile time
        - Returns an Error byte with (8) error conditions for user evaluation
        - Returns both received and computed checksum of sensor data

I believe the source code is well commented, so it should be fairly easy to use and understand.
I have included Notes and Warnings within the code to call attention to how to use the library effectively.

I hope you find this library beneficial.

BTW:

For those who are interested, I do have a PBP v3 only library that makes the use simpler, in my opinion.
Use:
The same as before. (3) Statements

Setup:
(1) Alias for each sensor used
(1) #Define to enable each sensor used
(1) #Define for the Oscillator Speed (This is additional to the standard PBP Define OSC x statement which is required)

This structure allows the compilation process to use #ifdef statements to select and compile only code for the sensors used,
and to select the proper PULSEIN_MAX value among other things.
This eliminates manually commenting out code for unused sensors to ensure more compact compiled code.

PBP_DHT_LIB:Attachment 7807
Attached Files

Magic Crystals

$
0
0
Hi All

How do I tell PBP 2.60 I am using a UART friendly Crystal....ie 3.6864Megs

Have now got project running using 4Megs.... But to further it and loose errors on RS232 would like to clock with no errors.

PBP is not liking being told it has a non default crystal ??

BR
Andy

Counter

$
0
0
Anyone have a simple example of how I can do something like this but with larger numbers then 65535?

Counter VAR WORD

Loop:

Counter = Counter + 1
lcdout $FE, line1,"Counter:", #Counter
PAUSE 100

Goto Loop

Tmr1

$
0
0
Hi all

Quick question

Thinking of using TMR1 on a 16f688 device for a time out (PIC stays on after a button push for 20mins then goes sleep)

Would this do that ?


Or would you suggest another method that may be better.... Operators are forgetting to turn field loggers off!!

Thank you
Andy

Servos not serving

$
0
0
I have two servos running off a 16F887 with no issues. Both toggle back and forth at roughly a 90 degree angle, in about 2 seconds.

I changed commands for a 12F675, mounted same on a prototype board with hefty 5 volt power supply/converter. With one servo connected (to GP1), everything is fine. With TWO connected, it's as if the time period was extended by a factor of 100: each servo does a little "tick" in about 1 second: at that rate, it will take 10 minutes or more to swing 90 degrees. Not only that but there is chattering where they can suddenly move 10 degrees. If I swap servos, same thing occurs. There is NO voltage drop on the MCU or servos when #2 is added. There is no NOISE on the power lines. Different servos create the same problem.

On a scope I cannot see any change whatsoever. The pulses are there, varying 1.0 to about 1.5 mS, and the overall period is 20 mS. (It's a little lower, frequency is about 65 Hz instead of 50 Hz). The program is attached for the 12F675. Even when the servos are chattering, the waveforms look okay.

Am I missing something? Is this a software or a hardware (ie MCU) problem?
Attached Files

TIMER1 intterupt of PIC 16f88 in C

$
0
0
Hi;
I'm trying to work ultrasonic sensor (HCSR-04) with PIC16f88. Since other interrutps (RB0 and INT0) were used I'm trying to operate HCSR04 with Timer1.When I connected trigger and echo to oscillator everyting seems OK. I can see trigger and corresponding echo related with distance. I think interrupt never occurs. When I read data sheet of microcontroller I understand as RB6 is related with TMR1 interrupt. Here is my code.


#include <xc.h>

#define _XTAL_FREQ 8000000 // crystal freq defined as 8 Mhz
int b;

void main()

{

OSCCON = 0b01111000;// 8 Mhz selected Internal Oscillator Freq

INTCON = 0b11000000; // GIE and PEIE is enabled

TRISB = 0b01000000;// RB6 selected as input(echo connected here)

T1CON = 0b01001000; // // System clock is derived from Timer1 oscillator with
// 1:1 prescale value and oscillator is enabled

PIE1bits.TMR1IE=1; // tmr1 overflow is enabled


ei(); // interrupt is enabled


while(1)

{

TMR1H = 0; //Setting Initial Value of Timer
TMR1L = 0; //Setting Initial Value of Timer
b = 0; // TM1 value is taken in b (look at interrupt at below)

RB5=1;
__delay_us(10); //trigger is sent
RB5=0;
__delay_ms(100); //Waiting for ECHO








if(b>2 && b<=20) // If measured distance is between 2-20 cm led
// at RB1 blinks
{
RB1=1;
__delay_ms(500);
RB1=0;
}

if(b>20 ) // If measured distance is higher than 20 cm led // at RB2 blinks
{
RB2=1;
__delay_ms(500);
RB2=0;
}

} // while closed

}// main closed

void interrupt echo()
{

if(PIR1bits.TMR1IF == 1) // Code enters if when flag condition occured

{
//PIE1bits.TMR1IE=0; // I also tried with that but it didn’t work

T1CONbits.TMR1ON = 1; //Start Timer

if(RB6 == 0) //If ECHO is LOW
{
T1CONbits.TMR1ON = 0; //Stop Timer
b = (TMR1L | (TMR1H<<8))/58; //Calculate Distance
}



PIR1bits.TMR1IF=0; //Clear PORTB On*Change Interrupt flag
//PIE1bits.TMR1IE=1;// Enable is opened if it is closed at top

}
}


PIC16F88 I2C Accelerometer Help

$
0
0
Im using a pic16f88 in conjuction with a MMA7455 accelerometer to make an auto leveling jack system. I have run into the problem of not being able to get the I2C functions from the inclinometer to register within the pic. Any help would be much appreciated. Below is the current code i have. I am not sure how to navigate the read/write functions correctly in order to get the value from the Y axis only. I know that the register is $07 but im not sure where to go from here.

Thanks!

#CONFIG
__cONFIG _CONFIG1, _INTRC_IO & _PWRTE_ON & _MCLR_OFF & _LVP_OFF
#endconfig
'
'Set the internal oscillator frequency (8 MHz)
Include "modedefs.bas"
DEFINE OSC 8
OSCCON.4 = 1
OSCCON.5 = 1
OSCCON.6 = 1


'Setup A/D Converter
ANSEL = 0 'turn off all A/D converters


TRISA= %00000010
TRISB= %00110000




up1 var PORTA.0 'motor1 up
up2 var PORTA.7 'motor2 up
button_level var PORTA.1
DPIN1 var PORTB.4 'data pin
DPIN2 var PORTB.5
CPIN1 var PORTA.2 'clock
CPIN2 var PORTA.3
y1 var byte[8]
y2 var byte[8]
led var PORTB.6


start:
clear
low button_level
low led
low up1
low up2


pause 100

if (button_level==1) then
goto level
else
goto start
endif

goto start


end


level:
clear
For y1 = 0 To 7
i2cwrite DPIN1, CPIN1, $07, y1, [y1]
pause 1
next y1

For y2 = 0 To 7
i2cwrite DPIN2, CPIN2, $07, y2, [y2]
pause 1
next y2


For y1 = 0 To 7
i2cread DPIN1, CPIN1, $07, y1, [y1]
PAUSE 1
next y1

For y2 = 0 To 7
I2CREAD DPIN2, CPIN2, $07, y2, [y2]
PAUSE 1
next y2

if (y1>y2) then
gosub blink
goto jack2up
endif

if (y1<y2) then
gosub blink
pause 500
gosub blink
goto jack1up
endif
goto start


jack2up:
high up2

For y2 = 0 To 7
I2CREAD DPIN2, CPIN2, $07, y2, [y2]
PAUSE 1
next y2
if (y1=<y2) then
low up2
else
goto jack2up
endif
goto start


jack1up:
high up1
For y1 = 0 To 7
i2cread DPIN1, CPIN1, $07, y1, [y1]
PAUSE 10
next y1

if (y1>=y2) then
low up1
else
goto jack1up
endif
goto start


blink:
high led
pause 500
low led
return

Quecetel M95 GPRS connection question

$
0
0
I am using M95 module from Quecetel. I am sending data to my server and facing a weird problem. I wonder if someone else can give me some idea.
I use AT+QISEND=128 to send 128 bytes at one time. Then I use AT+QISACK to see if all 128 bytes have been acknowledged. This process is in a loop.
BUT after like 512 (rarely 640 as well) bytes the connection closes by itself. Does anyone have any idea what setting I might be missing?

AT Command manual is at: http://www.sos.sk/a_info/resource/c/...5_ATC_V1.0.pdf

A mine of information

$
0
0
Searching microchip site for more detailed info on watchdog I came across this link:

https://microchip.wikidot.com/8bit:wdt

Which is a real mine of interesting information, so I thought It was nice to bring it to the attention of the forum.

Cheers

Al.
Viewing all 4787 articles
Browse latest View live