elphi
Joined: 17 Apr 2007 Posts: 20 Location: tijuana,bajacalifornia,mexico
|
mplab sim vs proteus in pic16f88 |
Posted: Tue Apr 17, 2007 8:21 am |
|
|
Hi, I’ve written the code below, it is a sine wave generator, this generator, must work with three different frequency , (this is a requirement in my project, witch actually is a project for my company).
It seems to work correctly, it must work correctly, but I have a doubt, I’ve simulated it in MPLAB SIM toll, and with the stimulus controller, I send the pulse to activate the external interrupt en RB0, an it works fine, but when I build the circuit in PROTEUS © (I don’t have the chip because I’ve just requested it) it doesn’t work, it just give the first frequency proposed.
Then my question is (finally), In witch simulator I have to trust MPLAB SIM or PROTEUS.
And please don’t tell me that I must build the circuit hardware ;).
Code: |
#include "16f88.h"
#include <stdlib.h>
#include"limits.h"
#define RETURN_HOME 0x2
#fuses NOWDT,XT, NOPUT, MCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, DEBUG, NOPROTECT, FCMEN, NOIESO
#use delay(clock=8000000)
#use fast_io(B)
int l=1,f=7,i,sine[40]={32 36 40 46 50 52 56 58 60 62 62 62 60 58 56 52 50 46 40 36 32 26 22 16 12 10 6 4 2 0 0 0 2 4 6 10 12 16 22 26};
#INT_EXT
void ext_isr()
{
switch (f)
{
case 4:///////////////4 + 6.5 del pic = 10.5us * 40 (steps) = 420 us = 2380.952 hz close to 2450 hz
f=7;break;
case 7://///////////// 7+ 6.5 del pic = 13.5us * 40 (steps) = 540 us = 1851.851 hz close to 1880 hz
f=19;break;
case 19://////////////19+ 6.5 del pic = 25.5us * 40 (steps) =1020 us = 980.3921 hz close to 1000 hz
f=4;break;
}
}
void main()
{
port_b_pullups(TRUE);
setup_adc(ADC_OFF);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
setup_oscillator(OSC_8MHZ);
setup_cpp1(CCP_OFF);
setup_counters (RTCC_INTERNAL,RTCC_DIV_2);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
EXT_INT_EDGE(0,L_TO_H);
SET_TRIS_b(0x1);
SET_TRIS_a(0x00);
while (true)
{
for(i=0;i<39;i++)
{
output_b(sine[i]);
delay_us(f);
}
}
}
|
_________________ Every little thing gonna be alright |
|
elphi
Joined: 17 Apr 2007 Posts: 20 Location: tijuana,bajacalifornia,mexico
|
Re: mplab sim vs proteus in pic16f88 |
Posted: Tue Apr 17, 2007 9:31 am |
|
|
Sorry, ive just noticed that PROTEUS send me a message telling me that TRISB and TRISA instructions are deprecated.
I suppose that I have to build the circuit in my protoboard, (when a get it). _________________ Every little thing gonna be alright |
|