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.

OSHON - Runtim error 11 division by Zero

Status
Not open for further replies.

SwingeyP

Member
Can anyone help me with this one please.

Code:
Dim data As Byte
Dim tonefreq As Word

TRISD = %11111111  'Set port D to input



'=============Main============
loop:
	idle:
		If PORTD.6 = 0 Then Goto idle  'tones are disabled, just idle

	data = ShiftLeft(PORTD, 2)
	data = data / 4  'Get the low 6 bits of Port D


	tonefreq = LookUp(0x43, 0x47, 0x4d, 0x52, 0x58, 0x5f), data
	
	FreqOut PORTB.1, tonefreq, 100
	
	Goto loop

Device = 16f877a

Every time I compile this I get the runtime error. Its only when I include the freqout line.

Regards - Paul
 
When I read the following from the manual, it says FREQOUT can be used in variable mode and constant mode, but I suspect not a combination of both.

"FREQOUT statement can be used to generate a train of pulses (sound tone) on the specified pin with constant frequency and specified duration. It has three arguments. The first argument is the pin that the tone will be generated on. The statement will setup the pin as an output pin. The second argument specify the tone frequency and it must be a constant in the range 1-10000Hz. The third argument defines the tone duration and it also must be a numeric constant in the range 1-10000ms. Choosing higher tone frequencies with low microcontroller clock frequency used may result in somewhat inaccurate frequency of the generated tones. FREQOUT statement can be alternatively used in 'variable mode' with Word data type variables instead of constants for the last two arguments. In this mode of usage the second argument is supposed to hold the half-period of the tone (in microseconds) and the third argument must hold the total number of pulses that will be generated. The following code will generate one second long tone on RB0 pin with 600Hz frequency:
FreqOut PORTB.0, 600, 1000 "

So i think the following would be valid ;

var first as word
var second as word

first = 0x58
second = 100

FreqOut PORTB.0, first, second
 
I have just found this thread when searching for the same problem.

I bought the compilers about 6 weeks ago, thinking they would be the answer as I did not feel like learning C after using various flavours of Basic since 1979.

I copied and pasted some code from Picaxe Basic into the editor, and started changing things, as the compiler threw up errors.

One block of code caused the division by zero error, and the compiler crashes.

I tried the AVR compiler, and the same things happens.

To me, it must be a bug, a compiler should not crash because of incorrect code, it should stop, hopefully with a meaningful message of what is wrong. At least with an indicator of the line with the error.

I reported it, and received an acknowledgement, but disappointingly I have not heard any more. I was even more disappointed to see that this problem is a year old on here.

I wonder if anyone has found a solution, apart from writing correct code from the start?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top