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.

The Machine Stops

Huckleberry

New Member
I have been playing with these things for years and using Oshonsoft products most of the time. Never had any major issues until now, so I suspect I have done something stupid and Dunning - Kruger is preventing me from seeing it. The program runs in the simulator with no problems but when presented to real application, it appears to halt. With oscilloscope, I see activity on PortB but the line1 information is not presented on the lcd. IF the execution continues, after approximately 1 second, PortC.3 should turn on (or off, depending on starting state) and does not. No further activity is detected on the outputs. Anyone see some glaring error that could cause this. (I have tried other PIC16F886 ICs with no difference).
TNX for any efforts made.

p.s.
Just FYI, the project is to provide some necessary services for 1946 Chevy truck

On edit, discovered I had attached the wrong .BAS file.
 

Attachments

  • 46AB.bas
    3.1 KB · Views: 136
Last edited:
Solution
I have looked several times.. I cannot see the interrupt setting for the Timer " TMR1IE = 1"
The interrupt cannot be called?? I shouldn't have worked in simulation.
Timer 1 interrupt is in the PIE1 register You should include these two before main.
TMR1IE = 1
TMR1IF = 0

Scratch that!! Just found it.. under alldigital..

I'll sim it in my simulator. Normally if it works in sim and not for real its probably OSC related.
I have looked several times.. I cannot see the interrupt setting for the Timer " TMR1IE = 1"
The interrupt cannot be called?? I shouldn't have worked in simulation.
Timer 1 interrupt is in the PIE1 register You should include these two before main.
TMR1IE = 1
TMR1IF = 0

Scratch that!! Just found it.. under alldigital..

I'll sim it in my simulator. Normally if it works in sim and not for real its probably OSC related.
 
Solution
Many thanks for your input, Ian. I made some changes to the config bits, now 0x20f5. But I haven't had a chance today to load the change and try it out. I will look into OSC settings and the automatic resets. I am still baffled by this behavior.
 
I have more for you... Config bits 1 00e4.. This is making DEBUG mode on. Your Brown out is also off.
(just in case you need it)



BUT!! you did have the internal clock set and that defaults to 4Mhz You haven't set a speed so the timings may well be out if you set 0x20F5 you are still using the internal clock but loosing pin RA6
If you use 0x20F4 you keep the RA6 as digital, but put this line in your code.

#define CLOCK_FREQUENCY = 4 just to ensure the timing is okay ( No idea what the default is..)
 
Hi Ian. BINGO! I noted your mention of 4MHz in first reply and suspicion of OSC settings. Mainly because my edit screen indicates clock of 8MHZ, I THEN looked at OSCCON contents in simulator and saw it set to 4MHZ and external clock. Looked for OSCCON in program and found it to be missing in action. added it with 8 MHZ and internal osc selected. I'm only using 2 inputs beyond PortB to LCD; one analog and one digital input. It now runs in circuit and I am down to fine tuning and finishing up.
Config(1) should have had internal oscillator selected while OSCCON.0 was 0, but circuit didn't function until manually set by program (OSCCON.0 = 1)...Something I will have to look into later.
What it all boils down to, is "You called it! and from long distance to boot"
TNX many
 
Good Morning? Ian. Clock speed in this application shouldn't be critical.
So, what happens is... tire is 34.5" diameter. Final gear ratio is 6.11:1. As that works out, the number of drive shaft revolutions per second is very, very close to the value of MPH. A proximity sensor detects Drive Shaft revolutions and TMR1 interrupts every 3573 revolutions to increment odometer. The same sensor is used for velocity. The numbers stay pretty low because the vehicle is WWII era Chevrolet truck and has a top speed of around 40 MPH. Replacement or repair of the non functioning instruments is ridiculously pricey. This little display will live under the dash unless I am driving; during which time a magnet will hold it on the dash. I'm not at all concerned about exceeding the number of EEPROM writes as at 74 I can't imagine driving it that many miles!
 
Okay! But its Miles per Hour.. You are doing the Miles and speed with the count on portc.0
which is timer dependent. "Count inputpin, ms time, physical count" so time is based on frequency.
 
Last edited:
You are right, of course. But normally the clk frequency set by the environment selection would agree with the OSCCON bit settings and one wouldn't need to think about it, (the perils of ASSUME noted, as came into play for me with this toy). Interesting, simulator here didn't change when I changed OSCCON to 8MHz. unless that even though sim was running at 4 MHz, (or was it?) the simulator displayed 8MHz. I think I'll just be happy that it runs and hope I can remember all this if problem arises again. Have a great week and I hope Great Britain is not beset with the terrible heat.
Thank you again for your assistance and counsel.
Best, Huck Keithline
Here in Kansas
 

Latest threads

New Articles From Microcontroller Tips

Back
Top