• Content Count

  • Joined

  • Last visited

Everything posted by c64

  1. Hi, Thanks, but I figured it out, I think. If using Timer3 instead it all works as expected. I think there's a conflict with Timer2 (and some PWM thing which is 'on' on default) and pin 10, which is used as SPI chip select.
  2. Hi, I'm using the ChipKit Wi-Fire board where I use an external ADC to capture data and transmit it over the SPI channel based on the Timer2 interrupt. Getting the Timer2 interrupt and ADC capture to work independently is no problem, it's only when I combine them together that something halts in an odd way. Below is my code, and basically, for testing purposes, I sample 50 samples, after which the Timer2 is disabled and I print out the numbers on the serial monitor. In the interrupt routine I set an interrupt flag, which will be caught in the main loop. /* CS: pin 10 MOSI: pin 11 MISO: pin 12 SCK: pin 13 */ #include <DSPI.h> #include <xc.h> /* contains Vector Name/Number Macros */ #include <sys/attribs.h> /* contains __ISR() Macros */ DSPI0 spi; const uint8_t chipSelect = 10; uint8_t i; uint16_t buffer[50]; uint16_t num1; uint8_t num2; const uint32_t SPI_frequency = 8000000; volatile uint8_t interrupt_flag; volatile uint8_t sample_counter; /* Define the Interrupt Service Routine (ISR) */ void __attribute__((interrupt)) myISR() { interrupt_flag = 1; clearIntFlag(_TIMER_2_IRQ); } void setup() { pinMode(4, OUTPUT); pinMode(chipSelect, OUTPUT); digitalWrite(chipSelect, HIGH); spi.begin(); spi.setTransferSize(DSPI_16BIT); spi.setSpeed(SPI_frequency); Serial.begin(9600); interrupt_flag = 0; sample_counter = 0; setIntVector(_TIMER_2_VECTOR, myISR); setIntPriority(_TIMER_2_VECTOR, 4, 0); clearIntFlag(_TIMER_2_IRQ); setIntEnable(_TIMER_2_IRQ); start_timer_2(); } void start_timer_2(void) { T2CONbits.TON = 0; /* Turn the timer off */ T2CONbits.TCKPS = 7; /* Set the prescaler */ TMR2 = 0; /* Clear the counter */ PR2 = 39062; // 10 kHz /* Set the frequency */ T2CONbits.TON = 1; /* Turn the timer on */ } void loop() { if(interrupt_flag == 1) { digitalWrite(4, !digitalRead(4)); digitalWrite(chipSelect, LOW); //num1 = spi.transfer(0x00); //digitalWrite(chipSelect, HIGH); buffer[i] = (uint8_t)(num1 >> 5); i++; interrupt_flag = 0; sample_counter++; Serial.println(sample_counter, DEC); } if(sample_counter == 10) { // Disable interrupts from Timer 2 IEC0bits.T2IE = 0; // Disable the peripheral T2CONbits.TON = 0; for(i = 0; i < 10; i++) { Serial.print(buffer[i], BIN); Serial.print("\t"); Serial.println(buffer[i], DEC); } while(1); } } This code doesn't work as intended, it seems to halt. The problem is the "if(interrupt_flag == 1)" part, which is only being called once, and then nothing more happens. Instead, if my routine in the main loop, in case of an interrupt, looks like this: if(interrupt_flag == 1) { digitalWrite(4, !digitalRead(4)); //digitalWrite(chipSelect, LOW); //num1 = spi.transfer(0x00); //digitalWrite(chipSelect, HIGH); buffer[i] = (uint8_t)(num1 >> 5); i++; interrupt_flag = 0; sample_counter++; Serial.println(sample_counter, DEC); }it works. Here I use GPIO 4 to give a square pulse train which I can monitor on an oscilloscope, and the serial monitor prints out all 0s, as expected. I've tested the Timer2 interrup as well as the external ADC reading through SPI separately, and they both work on their own. It just seems to fail when I combine them. Any ideas?
  3. Hi JColvin, Thanks for being on the case, I appreciate it. I read the errata earlier today, and it struck me that I can't expect higher rates than 125 ksps (or thereabout). But I guess this is for a 10 bit resolution? Do you happen to know what the expected rate is for an 8 bit resolution? I may have to go for an external ADC with an SPI channel if 125 ksps is the max. And then I read that the SPI channel itself has some pre-production problems haha. But I guess the SPI clock of 27 MHz ought to be enough to get a data throughput of 1.6 Mbps. I should probably just test it with a logic analyzer. Also, do you happen to know if there are any planned release dates for chips that solve the ADC shortcomings? Thanks!
  4. Hi, I have a ChipKit Wi-Fire board and using MPIDE 0150 (2015-03-18 build). One reason I picked this board was because the MCU has an ADC which can support sampling rates up to 500 ksps (for my project I would need around 200 ksps, 8 bit resolution). When I do a simple test and capture the time (micros()) before an after the analog read, I end up with a time difference of 2469 us, which means a meager ADC sampling rate of 405 sps. Why is it so slow? How can I achieve rates up to 200 ksps with MPIDE and the built in libraries? I found an article for the Arduino board, where someone has boosted up the sampling rate by going around the analog read library: http://www.microsmart.co.za/technical/2014/03/01/advanced-arduino-adc/ Would I have to do something similar in my case? Has anyone done this for the ChipKit boards and could share some code? I would assume there must be more people than myself who has the need for a fast ADC. The code I wrote to test the analog read speed is as follows: int sensorPin = A12; int sensorValue = 0; int start_time; int end_time; void setup() { Serial.begin(9600); } void loop() { start_time = micros(); sensorValue = analogRead(sensorPin); end_time = micros(); Serial.println(end_time-start_time, DEC); while(1); }
  5. Hi, I just downloaded the newest release from the link you sent me, and now it works like a charm! Thanks!
  6. Hi, Yes, I created a folder Libraries in my mpide folder. Inside Libraries I placed the unzipped delPck folder, which contains all 5 libraries. I've restarted MPIDE, as well as my computer, and I can access all the examples from the menu, so it seems as if the libraries have been included properly. But I still can't compile, still getting the same error message. If I place the MRF24G.h file in the same folder as the MPIDE project, and change the line to #include "MRF24G.h" (instead of the <> enclosure signs), the error message now refers to the second h file that is supposed to be included.
  7. Hi, I just bought the Chipkit Wi-Fire board and trying to use the DEIPcK examples that are provided on Digilent's website in MPIDE. However, when I try to compile an example program, for example WiFiScan, I get the following error message: WiFiScan.cpp:55:101: fatal error: MRF24G.h: No such file or directorycompilation terminated. MRF24G.h is the first h file that the program tries to load. I've included the DEIPcK libraries in the way that is described on this website: http://chipkit.net/started/learn-basics/party-libraries/ Any suggestions?