Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how i can implement output_b(SINE_WAVE[i]) in mikroc

Status
Not open for further replies.

khatus

Member level 2
Member level 2
Joined
Oct 7, 2017
Messages
45
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
339

how i can implement output_b(SINE_WAVE) in mikroc

I have found a code written in CCS C.My question is how i can implement it in mikroc

Code:
int i
CONST unsigned int SINE_WAVE[30] = {
0b00010000, 0b10010000, 0b01010000, 0b11010000, 0b00110000, 0b10110000, 
0b01110000, 0b11110000, 0b01110000, 0b10110000, 0b00110000, 0b11010000, 
0b01010000, 0b10010000, 0b00010000, 0b11100000, 0b01100000, 0b10100000, 
0b00100000, 0b11000000, 0b01000000, 0b10000000, 0b00000000, 0b10000000, 
0b01000000, 0b11000000, 0b00100000, 0b10100000, 0b01100000, 0b11100000};
main()
{
for(i=0;i<30;i++)
{
output_b(SINE_WAVE[i]);
}
}

Here how i can implement output_b(SINE_WAVE); function in mikroc
 

khatus

Member level 2
Member level 2
Joined
Oct 7, 2017
Messages
45
Helped
1
Reputation
2
Reaction score
0
Trophy points
6
Activity points
339
i want to convert this code to mikroc

Code:
#include <16F88.h>
#fuses INTRC_IO,NOWDT,NOPROTECT,NOLVP,PUT,CCPB3
#use delay(clock=8000000)

int i, j;

CONST unsigned int SINE_WAVE[30] = {
0b00010000, 0b10010000, 0b01010000, 0b11010000, 0b00110000, 0b10110000,
0b01110000, 0b11110000, 0b01110000, 0b10110000, 0b00110000, 0b11010000,
0b01010000, 0b10010000, 0b00010000, 0b11100000, 0b01100000, 0b10100000,
0b00100000, 0b11000000, 0b01000000, 0b10000000, 0b00000000, 0b10000000,
0b01000000, 0b11000000, 0b00100000, 0b10100000, 0b01100000, 0b11100000};

#INT_RTCC
void main_wave() {   
    if (i++ == 29)
        i = 0;
    output_b(SINE_WAVE);
}

#INT_TIMER2
void TIMER2_isr() {    
    if (j++ == 29)
        j = 0;
    output_a(SINE_WAVE[j]>>4);
}

void main(void) {
    i = 0;
    j = 0;
    setup_adc_ports(NO_ANALOGS);    // Turn off analogue inputs
    setup_oscillator(OSC_8MHZ | OSC_INTRC);   // Use internal 8MHz osc 
    set_timer0(0);

    setup_counters( RTCC_INTERNAL, RTCC_DIV_1 | RTCC_8_BIT);
        // about 258.7Hz
    
        setup_timer_2( T2_DIV_BY_4, 65, 1 );
        // 65 gives 250.8Hz

        enable_interrupts(INT_TIMER0);
        enable_interrupts(INT_TIMER2);
    enable_interrupts(GLOBAL);
    
    while(TRUE)
    {
        delay_ms(1);
    }
   
        disable_interrupts(INT_RTCC);
}
 
Last edited by a moderator:

kgavionics

Full Member level 3
Full Member level 3
Joined
Jun 12, 2012
Messages
165
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Activity points
2,454
I only know standard C, but I think the output_a is just a function to send the values of the table to a single pin. You can use either bit banging or another serial protocol to send the value out!
 

FvM

Super Moderator
Staff member
Advanced Member level 7
Joined
Jan 22, 2008
Messages
50,985
Helped
14,630
Reputation
29,536
Reaction score
13,739
Trophy points
1,393
Location
Bochum, Germany
Activity points
291,718
but I think the output_a is just a function to send the values of the table to a single pin.
No. It's a build-in compiler function sending an 8-bit number to port A pins. The code assumes a 8-bit parallel DAC connected to the port.
 

betwixt

Super Moderator
Staff member
Advanced Member level 7
Joined
Jul 4, 2009
Messages
15,793
Helped
5,085
Reputation
10,195
Reaction score
4,947
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
133,745
... wouldn't that just output the upper 4 bits of the value and ignore the lower one?
I'm not familiar with MikroC, it doesn't run on my OS but periodically reading a table and sending its contents to a port is hardly rocket science.

Brian.
 

kgavionics

Full Member level 3
Full Member level 3
Joined
Jun 12, 2012
Messages
165
Helped
7
Reputation
14
Reaction score
11
Trophy points
1,298
Location
Alberta.Canada
Activity points
2,454
... wouldn't that just output the upper 4 bits of the value and ignore the lower one?
I'm not familiar with MikroC, it doesn't run on my OS but periodically reading a table and sending its contents to a port is hardly rocket science.

Brian.
Yeah, that what I thought too!
Sending or receiving data from port to another is one of the first step you learn in microcontroller world!
The problem, that so many people don't take the time to learn things from the ground up! And, that's why they use compilers that do most of the job for them, unlike assembler or standard C!
 

paulfjujo

Advanced Member level 4
Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,459
Helped
296
Reputation
592
Reaction score
279
Trophy points
1,363
Location
France 01800
Activity points
10,409
hello,

where is the init of PORTA ?

TRISA=0;
PORTA=(SINE_WAVE[j]>>4);

look at this 16F88 MikroC version ... not tested
 

Attachments

  • 16F88_example.c.txt
    2.3 KB · Views: 31

betwixt

Super Moderator
Staff member
Advanced Member level 7
Joined
Jul 4, 2009
Messages
15,793
Helped
5,085
Reputation
10,195
Reaction score
4,947
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
133,745
In the original code and the 16F88 example only four bits are used. The '>>4' part of the code just moves the upper bits to the lower bit positions. How that is used in the circuit depends on how the DAC is wired. If you really only want to use 4 bits, change the look up table and then you can omit the bit shift in software.

Note that a 4 bit sine wave only has 16 levels so it will look more like a staircase than a smooth curve. As all the port bits are used, why not also increase accuracy by using all the bits in the look-up table?

Brian.
 

paulfjujo

Advanced Member level 4
Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,459
Helped
296
Reputation
592
Reaction score
279
Trophy points
1,363
Location
France 01800
Activity points
10,409
Hello,

you defined timers by frequency ! it is not usual
Timers are defined by time units !
so i started ,in my example , with 4mS periode for timers (because ~250Hz indication)
in this case , to explore the 30 steps => 30x4=120mS
it means Sinus defined for 8.33Hz
This frequency output is enough low to use
=> PWM instead of DAC ....

Other MCU , as PIC16F1615-16F1619 has a 8 bits DAC output 256 levels
18F26K22 5bit DAC outputs 32 levels
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top