Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

newbe frustration

Status
Not open for further replies.

Russlk

New Member
I expected this program to run forever, but about 3 seconds after applying power, the clock starts and runs for 2 seconds, then stops. When I remove power, the clock starts again and runs until it is out of voltage. Am I doing something wrong, or are these devices just freaky?

Device = 12f675
xtal =4
ALL_DIGITAL = TRUE
TRISIO = %000000

LOW PORTB.1
LOW PORTB.5
low portb.2
loop:
high portb.2
low portb.2
goto loop
end
 
I can't comment on the code, as it's not written in assembler, so it depends whatt he compiler generates, but it's most liekly that you ARE doing something wrong.

But your problem might lie with the hardware?, or with the configuration fues?.
 
This is the .ASM file, it looks strange to me. I tried programming with all timers enabled and brownout detect enabled, and the clock starts immediatly and runs for about 6 seconds.

;*******************************************************
;* Code Produced by the *
;* PROTON+ LITE Compiler. Version 3.0 *
;* Copyright Rosetta Technologies/Crownhill Associates *
;* Written by Les Johnson. 2004 *
;*******************************************************
NOLIST
#include "C:\PROGRAM FILES\PROTONIDELITE\SOUND TEST.PBP"
LIST

F1_SOF equ $ ; SOUND TEST.BAS
F1_000015 equ $ ; in [SOUND TEST.BAS] ALL_DIGITAL = TRUE
Bsf STATUS,5
ram_bank = 1
Clrf ANSEL
Movlw 7
Bcf STATUS,5
ram_bank = 0
Movwf CMCON
F1_000016 equ $ ; in [SOUND TEST.BAS] TRISIO = %000000
Bsf STATUS,5
ram_bank = 1
Clrf TRISIO
F1_000018 equ $ ; in [SOUND TEST.BAS] LOW PORTB.1
Bcf STATUS,5
ram_bank = 0
Bcf PORTB,1
Bsf STATUS,5
ram_bank = 1
Bcf TRISB,1
F1_000019 equ $ ; in [SOUND TEST.BAS] LOW PORTB.5
Bcf STATUS,5
ram_bank = 0
Bcf PORTB,5
Bsf STATUS,5
ram_bank = 1
Bcf TRISB,5
F1_000020 equ $ ; in [SOUND TEST.BAS] low portb.2
Bcf STATUS,5
ram_bank = 0
Bcf PORTB,2
Bsf STATUS,5
ram_bank = 1
Bcf TRISB,2
LOOP
Bcf STATUS,5
ram_bank = 0
F1_000022 equ $ ; in [SOUND TEST.BAS] high portb.2
Bsf PORTB,2
Bsf STATUS,5
ram_bank = 1
Bcf TRISB,2
F1_000023 equ $ ; in [SOUND TEST.BAS] low portb.2
Bcf STATUS,5
ram_bank = 0
Bcf PORTB,2
Bsf STATUS,5
ram_bank = 1
Bcf TRISB,2
F1_000024 equ $ ; in [SOUND TEST.BAS] goto loop
Bcf STATUS,5
ram_bank = 0
Goto LOOP
F1_000025 equ $ ; in [SOUND TEST.BAS] end
Pb@lb2
Sleep
Goto Pb@lb2
F1_EOF equ $ ; SOUND TEST.BAS
END
 
From the basic code you shown in the first post, it appears that:

You want Port B.1 and port B.5 to be set low, and you want Port B.2 to be going from low to high at maximum speed.

Keep in mind that not all chips are designed to handle ridiculously high speeds. So you might want to do one of the following: make the clock of the CPU (or microcontroller) slower, add some timer loops. That is, add code that determines when a certain amount of time has passsed.

and another thing, NOTHING runs forever on batteries. Batteries die! :lol:
 
I don't really want portb.2 to switch as fast as possible, I am just trying to determine the delay required for 2500 Hz. The first time I got this program to run, the frequency was 2300 hz, this time it is 100kHz. I wonder if I try a third 12F675 if the frequency will be different still?
 
I removed two statements from the basic program, now the clock runs continuously. Can any one explain?

Device = 12f675
xtal =4

LOW PORTB.1
LOW PORTB.5
low portb.2
loop:
high portb.2
low portb.2
goto loop
end

But, with this program the clock does not run, pin 2 goes high but pin 7 does not. I hate to think that I have to learn to program in assembler!
 

Attachments

  • test_181.gif
    test_181.gif
    40.1 KB · Views: 750
Russlk said:
I don't really want portb.2 to switch as fast as possible, I am just trying to determine the delay required for 2500 Hz. The first time I got this program to run, the frequency was 2300 hz, this time it is 100kHz. I wonder if I try a third 12F675 if the frequency will be different still?

Why not just make an external clock with a known frequency and connect it to the clock input of the microcontroller?

Determining the delay of a given frequency with a microcontroller is a waste of money.

But if you were to do it, the answer would have to be the same units as the external clock. For example, if the external clock is set at 0.1Hz (10 second delays), then your results will be measured in 10's of seconds (or if there is such word: decasecond)

If you wanted a timer, why not make a simple timer circuit and have the output of it feed a bit of a data port, and then in your program, you would detect when the bit is on, and then make an endless loop until the bit is off.
 
It doesn't perform as you expect, because you are either sending completely wrong intructions to it, or the microcontroller and/or the hardware attached to it is not connected properly. If any chip is hot, chances are that maybe your microcontroller is not receiving the proper instructions from the PC.

As for the external clock, that can be made with a simple 555 timer.

Once again, I don't use PIC's and I think yours is a PIC, so I can't tell you what commands to use.
But if you can translate my above suggestion into commands suitable for your microcontroller, then you should have a working unit.
 
Russlk said:
That sounds easy, Mstechca, but the problem is that the microcontroller does not perform as I expect, so I have no confidence that what you say will even work.

did you look at the datasheet?

the 12f675 does not have a portB!
it has GP0-GP6

also pin7 (GP0) is an analog pin, did you set the reg to make it digital?

don't loose confidence in pics, you just need to learn them!
 
Thanks for the info, Spindrah. I did not know if the assembler recognized a difference between portb and gpio; apparently not because when I changed the designation there was no difference.

This program runs, but pin 7 (GP0) does not go high. If I remove loop2, then pin 7 does go high. Can anyone explain that?

device = 12F675
xtal = 4

loop:
high gpio.5 'pin 2
high gpio.0 'pin 7
low gpio.1 'pin 6
loop2:
high gpio.1
delayms 63
low gpio.1
delayms 63
goto loop2
goto loop
end
 
But you still didn't set pins as output?
when you first start the pic, the analog pins will be in analog input mode!

try:

trisio = %00000000
or
ALL_DIGITAL = TRUE

before your code
 
I think this has to do with your config settings. The reason I think this is because it is unclear what you are using to clock the PIC. In your code I see you state a 4MHz crystal, but in the config settings in the photo show INTOSC with clock out. (Yes, the int osc runs at 4MHz. too.)
I'd spend some time reading over the data sheet. These little pics, if I remember, have a preset calibration value. See page 58 of the data sheet:
10.2.5.1 Calibrating the Internal Oscillator
A calibration instruction is programmed into the last
location of program memory. This instruction is a
RETLW XX, where the literal is the calibration value.
The literal is placed in the OSCCAL register to set the
calibration of the internal oscillator. Example 10-1
demonstrates how to calibrate the internal oscillator.
For best operation, decouple (with capacitance) VDD
and VSS as close to the device as possible.
They also tell you :
Note: Erasing the device will also erase the preprogrammed
internal calibration value for
the internal oscillator. The calibration value
must be saved prior to erasing part as
specified in the rfPIC12F675 Programming
specification.

Then, they go on to tell you exactly how to do this:
Code:
bsf STATUS, RP0 ;Bank 1
call 3FFh ;Get the cal value
movwf OSCCAL ;Calibrate
bcf STATUS, RP0 ;Bank 0

Also, it this LED is flashing, I think it would flash so quickly you wouldn't see it, as you have no delay to keep it on, or off. At least, as far as I can see, but this thread does not seem so clear... How do you tell if the pin goes high? Are you using a scope?

Hope this at least points you in the right direction.
Best wishes,
Robert
 
This program runs, but pin 7 (GP0) does not go high. If I remove loop2, then pin 7 does go high. Can anyone explain that?

device = 12F675
xtal = 4

loop:
high gpio.5 'pin 2
high gpio.0 'pin 7
low gpio.1 'pin 6
loop2:
high gpio.1
delayms 63
low gpio.1
delayms 63
goto loop2
goto loop
end

Either the assembler program you are using has a bug (sending the wrong commands to the device), or the hardware you are using is either faulty or configured for only certain software.

Have you tried new chips?
 
Russlk said:
Yes, I tried that long ago, it doesn't work. Besides, High & Low sets the pin as output.

but it does not take it out of analog
you must get out of analog mode
the prog you have won't work

try

ansel = %00000000

that will make all pins digital
 
Thanks for your reply, Robert, but I think I have found a solution for my frustration. I went back to using PICBASIC PRO. The free version does not support 12F675 so I had to program a 16F627A (a lot more capability than I need). However, the program ran perfectly the first time, so down with PROTON IDE LITE!
 
Strange things still happen. It seem there is a BIG difference in assemblers. The same program written and assembled in Proton IDE LITE is nothing like the same program written and assembled in PICKBASIC PRO.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top